AS3 placing movie clips on the stage

I’m using AS3 to place movieclips onto Flash’s stage…

The code I have looks something like this:


import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

var numberOfObjectsToDisplay:int	= 10;		// number of objects to display in total
var durationOfTimeOnScreen:int		= 13;		// time on screen in seconds

function fatController():void{
	var i:int;
	var thingies:Array = new Array();

	thingies[0] = new tableSmall();
	thingies[1] = new basketLarge();
	thingies[2] = new basketLarge();
	thingies[3] = new basketLarge();
	
	
	setTimeout(placeObject, 3000,		thingies[0],	stage.stageWidth+450,	300);
	setTimeout(placeObject, 3000,		thingies[1],	stage.stageWidth+100,	215);
	setTimeout(placeObject, 8000,		thingies[2],	stage.stageWidth+100,	150);
	setTimeout(placeObject, 9500,		thingies[3],	stage.stageWidth+100,	150);
	
	
}

function placeObject(obj:DisplayObject, posX:int, posY:int):void
{	trace('placed');
	this.addChild(obj);		// add this object to the stage
	
	obj.x=posX;				// move to X-Co-ordinate
	obj.y=posY;				// move to Y Co-ordinate
	var xMove:Tween = new Tween(obj, "x", None.easeIn, obj.x, stage.stageWidth-stage.stageWidth-450, durationOfTimeOnScreen, true);

	obj.addEventListener(MouseEvent.ROLL_OVER, killObject);
}

function killObject(e:MouseEvent) {
	e.target.gotoAndStop(2);
}

// start everything...
fatController();

This code places movie clips just off the right hand side of the stage, and they are tweened so that they animate to a position that is just off the left hand side of the stage.

I have a couple of questions…

I have manually placed a movieclip on the stage with instance name “skullCursor” - it follows your cursor with this code:


// make skull follow mouse movements
skullCursor.startDrag(true);
Mouse.hide();

My problem is that it is behind the objects that are being placed by the AS3 code. I want it to be in front of them… Does anyone know how I would do this?

Currently when the player moves their cursor over the movie clips that AS3 is placing on the stage, they disappear. However the movie clip is not actually removed from the stage, it simply plays to a blank frame in its timeline to give this illusion. How do I tell Flash to remove the movie clip from the stage rather than just give the illusion that it is gone?

And one last thing… When the player moves their cursor over the movie clips that AS3 is placing, I want the movie clip that is attached to the cursor to gotoAndPlay certain frames of its timeline.

I hope you can help me work this out…!

Thanks in advance to anyone that can point me in the right direction! :slight_smile: