# Loading moviclip into movieclip

**URL:** <https://forum.kirupa.com/t/loading-moviclip-into-movieclip/307649>\
**Category:** Uncategorized\
**Created:** [April 7, 2010, 3:43pm UTC](https://forum.kirupa.com/t/loading-moviclip-into-movieclip/307649 "2010-04-07T15:43:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![radams2000](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@radams2000](https://forum.kirupa.com/u/radams2000)\
**Post date:** [April 7, 2010, 3:43pm UTC](https://forum.kirupa.com/t/loading-moviclip-into-movieclip/307649/1 "2010-04-07T15:43:25Z")

</div>

Hi  
I can get the movieclips into the container movieclip, but they’re supposed to float around within the boundaries of container movieclip  
Unfortunatly they just float off stage  
I THINK THE IMPORTANT PART IS AT THE END OF THE SCRIPT IN THE ON ENTER FRAME HANDLER  
Any pointers?  
Thanks

[AS]import fl.transitions.Tween;  
import fl.transitions.TweenEvent;  
import fl.transitions.easing.\*;  
var boxStartY:Number;  
var boxStartX:Number;  
var boxAlpha:Number = .7;  
var boxScale:Number = .3;  
var boxes:Array = new Array();  
var xmlFile:String = “images.xml”;  
//create boxes array to put mc’s into  
function randomize(min:Number, max:Number):Number {  
var range = max-min;  
var resultRandom = Math.random()\*range;  
resultRandom += min;  
return resultRandom;  
}

//initialise photo boxes  
function init():void {

var loader:URLLoader = new URLLoader();  
loader.addEventListener(Event.COMPLETE, loadXML);  
loader.load(new URLRequest(xmlFile));  
function loadXML(e:Event):void {  
XML.ignoreWhitespace = true;  
var xml:XML = new XML(e.target.data);  
var list:XMLList = xml.product;  
for (var i:int = 0; i \< list.length(); i++){  
var element:XML = list\*;  
trace(element.url+" "+element.desc);  
var newBox:myMC1 = new myMC1();  
newBox.name = “box” + i;  
newBox.x = randomize(5, container.x);  
newBox.y = randomize(5, container.y);  
newBox.scaleX = .3;  
newBox.scaleY = .3;  
newBox.speedX = randomize(1,2);  
newBox.speedY = newBox.speedX;  
newBox.speedR = randomize(-2,4);  
newBox.alpha = boxAlpha;  
newBox.select = false;//var to toggle when selected

var l:Loader = new Loader();  
l.contentLoaderInfo.addEventListener(Event.INIT, loaded);  
l.load(new URLRequest(element.url))  
function loaded(evt:Event){  
var targetLoader= evt.target.loader;  
targetLoader.x = -(targetLoader.width / 2);  
targetLoader.y = -(targetLoader.height / 2);

}  
newBox.addChild(l)  
newBox.addEventListener(MouseEvent.CLICK, enlarge);  
newBox.mouseChildren = false//mouse events won’t work  
//if not used  
boxes.push(newBox);//put in to array  
container.addChild(newBox);//adds to a movieclip on the stage

}  
}  
}

function enlarge(evt:MouseEvent):void {  
var theMC:MovieClip = MovieClip(evt.target);  
if (!theMC.select) {  
theMC.speedX = 0;//stop rotation, and scale up to centre  
theMC.speedY = 0;  
theMC.speedR = 0;  
var rotationTween:Tween = new Tween(theMC, “rotation”, None.easeOut, theMC.rotation, 0, .6, true);  
var scaleXTween:Tween = new Tween(theMC, “scaleX”, None.easeNone, theMC.scaleX, 1, .5, true);  
var scaleYTween:Tween = new Tween(theMC, “scaleY”, None.easeNone, theMC.scaleY, 1, .5, true);  
var alphaTween:Tween = new Tween(theMC, “alpha”, None.easeInOut, theMC.alpha, 1, 1, true);  
var locXTween:Tween = new Tween(theMC, “x”, None.easeOut, theMC.x, container.height/2, .5, true);  
var locYTween:Tween = new Tween(theMC, “y”, None.easeOut, theMC.y, container.width/2, .5, true);  
theMC.parent.setChildIndex(theMC,theMC.parent.numChildren-1);//bring to the top of the pile  
theMC.select = true;  
} else {

theMC.speedX = randomize(1,2);  
//reset  
theMC.speedY = theMC.speedX;  
theMC.speedR = randomize(-2,4);  
scaleXTween = new Tween(theMC, “scaleX”, None.easeNone, theMC.scaleX, boxScale, 1, true);  
scaleYTween = new Tween(theMC, “scaleY”, None.easeNone, theMC.scaleY, boxScale, 1, true);  
alphaTween = new Tween(theMC, “alpha”, None.easeInOut, theMC.alpha, boxAlpha, 1, true);  
theMC.select = false;  
}  
}  
//BOXES IS THE ARRARY THAT HOLDS THE IMAGE NAMES AND SHOULD TELL  
//THEM TO FLOAT IN THE OPPOSITE DIRECTION WHEN CONDITIONS ARE MET  
container.addEventListener(Event.ENTER\_FRAME, moveIt);  
function moveIt(evt:Event):void {  
//if the  
//Loop through the boxes array  
for (var i = 0; i \< boxes.length; i++) {  
//Update the y position  
boxes\*.x += boxes\*.speedX;  
boxes\*.y += boxes\*.speedY;  
boxes\*.rotation += boxes\*.speedR;  
if (boxes\*.y \<=0||boxes\*.y \>= container.height) {  
boxes\*.speedY _= -1;  
boxes_.speedR _= -1;  
}  
if (boxes_.x \<=0||boxes\*.x \>= container.width) {  
boxes\*.speedX _= -1;  
boxes_.speedR \*= -1;  
}  
}  
}  
trace(container.width)

init();  
[/AS]
