Hi,
I’ve made a character that I want to move from point A to point B.
Then when its at point B I want it to “teleport” back to point A. And go to point B again.
my code is
package {
//Importeer benodigde classes
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite {
public var myDuck:Eend;
public var myPduck:Eend;
public var Wing:Eend;
public var myCursor:Cursor;
public var yourScore=new Score ;
public var myScore=0;
public var theScore:TextField = new TextField();
public var myFormat:TextFormat = new TextFormat();
private var angle:Number=0;
private var range:Number=800;
private var speed:Number=0.03;
//Maak constructor functie
public function Main() {
init();
}
public function addScore(points) {
myScore+=points;
yourScore.Updatescore(myScore);
}
//Initialiseer de applicatie
private function init():void {
addChild(yourScore);
theScore.text = ("Punten");
theScore.x=700;
theScore.y=10;
theScore..selectable = false; ;
addChild(theScore);
myFormat.color=0xFF0000;
myFormat.size=24;
theScore.setTextFormat(myFormat);
//Groene eend
myDuck = new Eend();
myDuck.x=200;
myDuck.y=300;
myDuck.scaleX=0.4;
myDuck.scaleY=0.4;
myDuck.inkleuren("0x22CC22");
addChild(myDuck);
//Paarse eend
myPduck = new Eend();
myPduck.scaleX=-0.4;
myPduck.scaleY=0.4;
myPduck.x=600;
myPduck.y=300;
myPduck.inkleuren("0x800095");
addChild(myPduck);
//Cursor
myCursor = new Cursor();
stage.addEventListener(MouseEvent.MOUSE_MOVE , movecrs);
function movecrs(event:MouseEvent) {
myCursor.x=mouseX;
myCursor.y=mouseY;
myCursor.visible=true;
addChild(myCursor);
Mouse.hide();
myCursor.mouseEnabled=false;
}
addEventListener(Event.ENTER_FRAME, beweegBeest);
addEventListener(MouseEvent.MOUSE_DOWN, stopbeest);
}
public function beweegBeest(e:Event):void {
myPduck.x=Math.cos(angle)*range;
angle+=speed;
if (myPduck.x<-100) {
removeEventListener(Event.ENTER_FRAME, beweegBeest);
myPduck.x=650;
}
}
public function stopbeest(e:Event):void {
removeEventListener(Event.ENTER_FRAME, beweegBeest);
myPduck.x=650;
if (myPduck.x=650) {
addEventListener(Event.ENTER_FRAME, beweegBeest);
}
}
}
}
Now the problem is… When the char gets to point B, it “teleports” to point A like I want it to. But then the movent wont start again… (I’ve got it to a point where it would go back to the -100 point and continu if clicked… so that wasn’t a solution :/… )
Anyone know A way how i can get it to do what i want?
Btw, how do you post actionscripcode… instead of code…