Сlicking on the car image, you can attach a trailer to it:
Below you can see my source code:
var trailer:MovieClip = new Trailer();
trailer.mouseEnabled = false;
trailer.x = 120;
trailer.y = 10;
var car1:MovieClip = new Car();
car1.name = "car1";
car1.x = 100;
car1.y = 50;
car1.addChild(trailer);
addChild(car1);
var car2:MovieClip = new Car();
car2.name = "car2";
car2.x = 100;
car2.y = 150;
addChild(car2);
var currentCar:MovieClip = car1;
stage.addEventListener(Event.ENTER_FRAME, onFrameEnter);
function onFrameEnter(evt:Event):void {
currentCar.x = mouseX;
}
addEventListener(MouseEvent.MOUSE_DOWN, onAddChild);
function onAddChild(evt:MouseEvent):void {
currentCar = evt.target as MovieClip; //casting
evt.target.addChild(trailer);
}
Below you can see my source code:
var trailer:MovieClip = new Trailer();
trailer.mouseEnabled = false;
trailer.x = 120;
trailer.y = 10;
var car1:MovieClip = new Car();
car1.name = "car1";
car1.x = 100;
car1.y = 50;
car1.addChild(trailer);
addChild(car1);
var car2:MovieClip = new Car();
car2.name = "car2";
car2.x = 100;
car2.y = 150;
addChild(car2);
var currentCar:MovieClip = car1;
stage.addEventListener(Event.ENTER_FRAME, onFrameEnter);
function onFrameEnter(evt:Event):void {
currentCar.x = mouseX;
}
addEventListener(MouseEvent.MOUSE_DOWN, onAddChild);
function onAddChild(evt:MouseEvent):void {
currentCar = evt.target as MovieClip; //casting
evt.target.addChild(trailer);
}
No comments:
Post a Comment