|
-
You could, but I can't open it here. If it's CS4, I can't open it at all.
I'd suggest keeping references to tn, ap, and cw at the class level, and making a function to set up the targets and mouse-up listeners. Call that function from the frame where the targets actually exist.
PHP Code:
package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.display.DisplayObject; import DragDrop; import TN; import AP; import CW;
public class DragGame extends MovieClip { private var tn:TN; private var ap:AP; private var cw:CW;
public function DragGame() { createPieces(); } private function createPieces():void { tn = new TN(); addChild(tn); tn.x = 169.9; tn.y = 90.8; tn.width = 370.9; tn.height = 68; tn.alpha = 0.3; ap = new AP(); addChild(ap); ap.x = 496.6; ap.y = 169.9; ap.width = 162.8; ap.height = 110.2; ap.alpha = 0.3; cw = new CW(); addChild(cw); cw.x = 44.8; cw.y = 193.1; cw.width = 197.0; cw.height = 94; cw.alpha = 0.3; } public function setUpTargets():void{ tn._targetPiece = ttn_mc; tn.addEventListener(MouseEvent.MOUSE_UP, checkTarget); trace(ttn_mc);
ap._targetPiece = tap_mc; ap.addEventListener(MouseEvent.MOUSE_UP, checkTarget); trace(tap_mc);
cw._targetPiece = tcw_mc; cw.addEventListener(MouseEvent.MOUSE_UP, checkTarget); trace(tcw_mc); }
private function checkTarget(event:MouseEvent):void { var ec:MovieClip = MovieClip(event.currentTarget); var target:DisplayObject = DisplayObject(ec._targetPiece); if(ec.hitTestObject(target)) { trace("whooooot!"); ec.x = target.x; ec.y = target.y; ec.removeEventListener(MouseEvent.MOUSE_UP, checkTarget); ec.disable(); } else { ec.x = ec._origX; ec.y = ec._origY; } } } }
call setUpTargets from the frame where the targets exist.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|