# Nesting Actionscript from external AS into file

**URL:** <https://forum.kirupa.com/t/nesting-actionscript-from-external-as-into-file/319874>\
**Category:** flash\
**Created:** [March 7, 2011, 4:23pm UTC](https://forum.kirupa.com/t/nesting-actionscript-from-external-as-into-file/319874 "2011-03-07T16:23:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ebreezesoccer23](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@Ebreezesoccer23](https://forum.kirupa.com/u/Ebreezesoccer23)\
**Post date:** [March 7, 2011, 4:23pm UTC](https://forum.kirupa.com/t/nesting-actionscript-from-external-as-into-file/319874/1 "2011-03-07T16:23:39Z")

</div>

If anyone could help me rework this actionscript i found in a tutorial I would appreciate it. I am wanting to nest it in the file instead of calling it externally. Below is the code.

Thanks

package  
{  
import flash.display.MovieClip;  
import flash.utils.Timer;  
import flash.events.Event;  
import flash.events.TimerEvent;

public class Main extends MovieClip  
{  
private var clips\_array:Array;

private const SPRING:Number=.1;

private var timer:Timer;

public function Main()  
{  
init();  
initTimer();  
}

private function init():void  
{  
stage.frameRate=31;

bg\_mc.x=0;  
bg\_mc.y=0;  
bg\_mc.width=stage.stageWidth;  
bg\_mc.height=stage.stageHeight;

clips\_array=new Array(mc\_clip\_0,mc\_clip\_1,mc\_clip\_2,mc\_clip\_3,mc\_clip\_4,mc\_clip\_5);  
}

private function initTimer():void  
{  
timer=new Timer(400,0);  
timer.addEventListener(TimerEvent.TIMER,go);  
timer.start();  
}

private function go(evt:TimerEvent):void  
{  
var n:Number=Math.floor(Math.random()\*clips\_array.length);  
var clip:MovieClip=new clips\_array[n];

clip.x=Math.random()\*stage.stageWidth;  
clip.y=-clip.height;  
clip.center=clip.x;  
clip.vel\_x=2+Math.random()\*10;  
clip.vel\_y=clip.vel\_x;  
clip.angle=0;  
addChild(clip);

clip.addEventListener(Event.ENTER\_FRAME,goDown);  
}

private function goDown(evt:Event):void  
{  
var acc\_x:Number=(evt.target.center-evt.target.x)\*SPRING;  
evt.target.vel\_x+=acc\_x;  
evt.target.x+=evt.target.vel\_x;  
evt.target.y+=15-evt.target.vel\_y;  
evt.target.rotation++;  
var sine:Number=Math.sin(evt.target.angle);  
evt.target.scaleX=sine;  
evt.target.angle+=.1;  
if(evt.target.y\>=stage.stageHeight+100)  
{  
evt.target.removeEventListener(Event.ENTER\_FRAME,goDown);  
var m:MovieClip=evt.target as MovieClip;  
removeChild(m);  
}  
}  
}  
}
