I found another method which is working easier than the Trigonometry that I was trying.
package {
import flash.display.MovieClip;
import fl.motion.BezierSegment;
import flash.events.MouseEvent;
import flash.geom.Point;
import PathObject;
import MenuButton;
public class PathExample extends MovieClip {
// variable to hold the path object
private var pathObj:PathObject;
// variables to hold the four menu buttons
private var menu1:MenuButton;
private var menu2:MenuButton;
private var menu3:MenuButton;
private var menu4:MenuButton;
public function PathExample() {
// constructor code
trace('document started');
// define a path for the pointer to follow
var path = new BezierSegment(new Point(100,100),
new Point(200,200),
new Point(300,200),
new Point(400,100));
// create an instance of the PathObject class
this.pathObj = new PathObject(path);
// add the PathObject to the stage
addChild(this.pathObj);
this.pathObj.SetTarget(0);
this.pathObj.SetTargetRotation(60);
// creat menu buttons, set thier positions, and add them to the stage
this.menu1 = new MenuButton();
this.menu1.x = 100;
this.menu1.y = 300;
this.menu1.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
addChild(this.menu1);
this.menu2 = new MenuButton();
this.menu2.x = 200;
this.menu2.y = 300;
addChild(this.menu2);
this.menu2.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
this.menu3 = new MenuButton();
this.menu3.x = 300;
this.menu3.y = 300;
addChild(this.menu3);
this.menu3.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
this.menu4 = new MenuButton();
this.menu4.x = 400;
this.menu4.y = 300;
addChild(this.menu4);
this.menu4.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
}
public function SetMenu(evt:MouseEvent)
{
// set values based on which of the buttons was pressed
if (evt.target == this.menu1)
{
this.pathObj.SetTarget(0.25);
this.pathObj.SetTargetRotation(60);
}
else if (evt.target == this.menu2)
{
this.pathObj.SetTarget(0.5);
this.pathObj.SetTargetRotation(30);
}
else if (evt.target == this.menu3)
{
this.pathObj.SetTarget(0.75);
this.pathObj.SetTargetRotation(-30);
}
else if (evt.target == this.menu4)
{
this.pathObj.SetTarget(1);
this.pathObj.SetTargetRotation(-60);
}
}
}
}
import flash.display.MovieClip;
import fl.motion.BezierSegment;
import flash.events.MouseEvent;
import flash.geom.Point;
import PathObject;
import MenuButton;
public class PathExample extends MovieClip {
// variable to hold the path object
private var pathObj:PathObject;
// variables to hold the four menu buttons
private var menu1:MenuButton;
private var menu2:MenuButton;
private var menu3:MenuButton;
private var menu4:MenuButton;
public function PathExample() {
// constructor code
trace('document started');
// define a path for the pointer to follow
var path = new BezierSegment(new Point(100,100),
new Point(200,200),
new Point(300,200),
new Point(400,100));
// create an instance of the PathObject class
this.pathObj = new PathObject(path);
// add the PathObject to the stage
addChild(this.pathObj);
this.pathObj.SetTarget(0);
this.pathObj.SetTargetRotation(60);
// creat menu buttons, set thier positions, and add them to the stage
this.menu1 = new MenuButton();
this.menu1.x = 100;
this.menu1.y = 300;
this.menu1.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
addChild(this.menu1);
this.menu2 = new MenuButton();
this.menu2.x = 200;
this.menu2.y = 300;
addChild(this.menu2);
this.menu2.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
this.menu3 = new MenuButton();
this.menu3.x = 300;
this.menu3.y = 300;
addChild(this.menu3);
this.menu3.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
this.menu4 = new MenuButton();
this.menu4.x = 400;
this.menu4.y = 300;
addChild(this.menu4);
this.menu4.addEventListener(MouseEvent.MOUSE_UP,SetMenu);
}
public function SetMenu(evt:MouseEvent)
{
// set values based on which of the buttons was pressed
if (evt.target == this.menu1)
{
this.pathObj.SetTarget(0.25);
this.pathObj.SetTargetRotation(60);
}
else if (evt.target == this.menu2)
{
this.pathObj.SetTarget(0.5);
this.pathObj.SetTargetRotation(30);
}
else if (evt.target == this.menu3)
{
this.pathObj.SetTarget(0.75);
this.pathObj.SetTargetRotation(-30);
}
else if (evt.target == this.menu4)
{
this.pathObj.SetTarget(1);
this.pathObj.SetTargetRotation(-60);
}
}
}
}
Update 4th November 2010
It works great but the Bezier curve only allows me 4 points, so my fifth menu can't be fitted into this solution. Looks like I have to go back to sorting out trigonometry.
No comments:
Post a Comment