[SIZE=3][COLOR=#000000][FONT=Arial]I want to duplicate the object when it’s clicked. So I will have 2 objects, 1 which stays the same and one which will follow mouse pointer to be dragged around. But what happened is that the clicked one will follow the mouse and don’t have any duplicates to stay. Really need solution to this. Thanks!
I’ve tried to make it like movingHero = new Hero1(); but since I don’t know which hero will be clicked so I can’t just use Hero1 from library right?. and If I use movingHero = heroClicked I only get the value of hero1 which is a var from Hero1 movieclip and the result is the hero clicked will still follow the mouse without any duplicates to stay. So, is there any way to call the movie clip from library the same as which hero was clicked in stage? [/FONT][/COLOR]
[/SIZE]
Code :
[SIZE=2]package {[/SIZE]
[SIZE=2] import flash.display.MovieClip[/SIZE]
[SIZE=2] import flash.events.MouseEvent[/SIZE]
[SIZE=2] import flash.events.Event[/SIZE]
[SIZE=2] import flash.display.Sprite[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] public class Hero {[/SIZE]
[SIZE=2] private var heroesArray:Array;[/SIZE]
[SIZE=2] private var heroContainer:Sprite = new Sprite;[/SIZE]
[SIZE=2] private var hero1:MovieClip = new Hero1();[/SIZE]
[SIZE=2] private var hero2:MovieClip = new Hero2();[/SIZE]
[SIZE=2] private var moveHero:Boolean = false;[/SIZE]
[SIZE=2] private var movingHero:MovieClip;[/SIZE]
[SIZE=2] private var _money:Money = new Money();[/SIZE]
[SIZE=2] private var _main:Main;[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] public function Hero(main:Main) [/SIZE]
[SIZE=2] { _main = main;[/SIZE]
[SIZE=2] heroesArray = [hero1,hero2];[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] public function playerMoving(e:Event):void[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2] if (moveHero == true)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2] movingHero.x = _main.mouseX;[/SIZE]
[SIZE=2] movingHero.y = _main.mouseY;[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] public function chooseHero(e:MouseEvent):void[/SIZE]
[SIZE=2] { [/SIZE]
[SIZE=2] var heroClicked:MovieClip = e.currentTarget as MovieClip;[/SIZE]
[SIZE=2] var cost:int = _main._money.money ;[/SIZE]
[SIZE=2] if(cost >= 10 && moveHero == false)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2] _main._money.money -= 10;[/SIZE]
[SIZE=2] _main._money.addText(_main);[/SIZE]
[SIZE=2] onClickHero(heroClicked);[/SIZE]
[SIZE=2] moveHero = true;[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] public function onClickHero(heroes:MovieClip):void[/SIZE]
[SIZE=2] { [/SIZE]
[SIZE=2] movingHero = heroes;[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] heroContainer.addChild(movingHero);[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] public function displayHero(stage:Object):void[/SIZE]
[SIZE=2] { [/SIZE]
[SIZE=2] stage.addChild(heroContainer);[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] for (var i:int = 0; i<2;i++)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2] stage.addChild(heroesArray*);[/SIZE]
[SIZE=2] heroesArray*.x = 37;[/SIZE]
[SIZE=2] heroesArray*.y = 80+i70;[/SIZE]
[SIZE=2] heroesArray.width=60;[/SIZE]
[SIZE=2] heroesArray*.height=55;[/SIZE]
[SIZE=2] heroesArray*.buttonMode = true;[/SIZE]
[SIZE=2] heroesArray*.addEventListener(MouseEvent.CLICK, chooseHero);[/SIZE]
[SIZE=2] heroesArray*.addEventListener(Event.ENTER_FRAME, playerMoving);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] [/SIZE]
[SIZE=2]}[/SIZE]