Make a Movie Clip on the Stage appear above a dynamically loaded Movie Clip
November 20, 2009
ActionScript3 | Flash
A while back, I worked on a flash game that teaches medical professionals how to find objects in a cardiac cart. A cart with 6 drawers isshown at left. When a drawer is clicked, it slides in from the top of the screen so that all the objects inside can be seen. The object of the game is to drag whichever object has been selected at random to a target at bottom right.

The original design allowed plenty of room for the drawers to move down to their open position without obscuring the target area.

But as time went on and more requirements came to light, the dimensions of the game had to be shortened so that the drawer overlapped the hand target when it was in its "open" position.


Ads by Google

Posted by ellen at November 20, 2009 12:33 PM VC-GUI.jpg

I thought I'd just move the target clip up over the level of the drawer but that turned out to be more complicated than I expected. The drawer is loaded into a loader instance on the stage. To make the hand appear above the loaded clip the hand clip must be added as a child to the loaded clip.

First, declared the symbol as a variable in the Document class, which is to say a variable on the Stage. Then in the loaded clip's INIT event handler function, add
stage.addChild(pathTo.yourSymbol);  
Doing this means that the loaded clip will be taken into account when determining what the topmost member of the Display list is.

Stage: "Cart" class

public class cart extends MovieClip
	{
	     public static var M:cart; //this instance of the cart class
	     public var loadedSwf:MovieClip;
	     public var theloader:drawerLoader = new drawerLoader();
	     public var closerBtn:MovieClip;
	     public var playAgainBtn:*;
	     public var invisBtn:*;
	     public var currentLoader:Loader;
	     public var isUnloaded:Boolean;
	     public var currentDrawer:Number;
	     public var correctItem;
	     public var currentItem;
	     public var feedbackArea:TextField;
	     public var instructionsArea:TextField;
	     public var xmlItemData:XML;
	     public var itemList:XMLList;
	     public var correctItems:String;
			var ori_x:Number;
			var ori_y:Number;
			 
var checkerTgt:MovieClip;
			 
			
	     public function cart():void
	      {	     
	        M = this;	
	        M.theloader.x = 310;
	        M.theloader.y = 10;
	         
	        instructionsArea = TextField(getChildByName("instructionsArea_dt"));
	        instructionsArea.text = "loading, please wait...";
	        feedbackArea = TextField(getChildByName("feedbackArea_dt"));
	        closerBtn = MovieClip(getChildByName("closeDrawer_btn")); 
	        closerBtn.buttonMode = true;
	        closerBtn.addEventListener(MouseEvent.MOUSE_DOWN, clickCloserBtnHandler);
	         closerBtn.alpha = 0;
	        M.theloader.addEventListener(MouseEvent.MOUSE_DOWN, itemMouseDownHandler);
	         M.theloader.addEventListener(MouseEvent.MOUSE_UP, stopDragItem); 
	        LoadXML();
	        M.playAgainBtn = MovieClip(getChildByName("playAgainBtn1"));
	        M.playAgainBtn.addEventListener(MouseEvent.MOUSE_DOWN, chooseAnotherItem); 
//setting this up for moving it on top of the loader in drawerHandle.as
	         M.checkerTgt = MovieClip(getChildByName("checkerTarget_mc")); 
etc....
INIT event handler in the Loaded clip's class
. . .
	     public function mouseDownHandler(evt:Event):void
		{
	            var currentHandle:String = evt.target.name;
		    dn = Number(currentHandle.substr(12,1));
		    cart.M.currentDrawer = dn;
		    var request:String = ("drawers/drawer"+dn+"moving.swf");
		   _loader = cart.M.theloader;
		   _loader.load( new URLRequest(request) );
		   cart.M.loadedSwf = MovieClip( _loader.content);
 _loader.contentLoaderInfo.addEventListener( Event.INIT, doneLoading );
			  }
		
		
	   public function doneLoading(event:Event):void 
	   {
           cart.M.loadedSwf = event.target.loader.content;
           stage.addChild( _loader);
	   cart.M.loadedSwf.isInited = true;
//this pops checkertarget up OVER the loader
	   stage.addChild(cart.M.checkerTgt); 
           }
  

Ads by Google


Ads by Google

 RSS   |   Contact Me


Ads by Google