# Attach Movie in AS3

**URL:** <https://forum.kirupa.com/t/attach-movie-in-as3/234131>\
**Category:** flash\
**Created:** [July 30, 2007, 7:53pm UTC](https://forum.kirupa.com/t/attach-movie-in-as3/234131 "2007-07-30T19:53:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Macadia](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@Macadia](https://forum.kirupa.com/u/Macadia)\
**Post date:** [July 30, 2007, 7:53pm UTC](https://forum.kirupa.com/t/attach-movie-in-as3/234131/1 "2007-07-30T19:53:06Z")

</div>

I would like to attach a movieclip to a file in AS3.  
Right now, I have a Sprite class named Ball.as that is used by the code.  
Instead, I would like to attach my own movieclip.  
Do you know how it’s possible?  
And if the movieclip is in a .fla file, how does it link to this file?

This is the code:  
package {  
import flash.display.Sprite;  
import flash.display.StageAlign;  
import flash.display.StageScaleMode;  
import flash.events.Event;  
import flash.events.MouseEvent;

```
public class DragAndMove1 extends Sprite {
	private var ball:Ball;
	private var vx:Number;
	private var vy:Number;
	private var bounce:Number = -.7;
	private var gravity:Number = .5;
	
	public function DragAndMove1() {
		init();
	}
	
	private function init():void {
		stage.scaleMode = StageScaleMode.NO_SCALE;
		stage.align = StageAlign.TOP_LEFT;
		ball = new Ball();
		ball.x = stage.stageWidth / 2;
		ball.y = stage.stageHeight / 2;
		vx = Math.random() * 10 - 5;
		vy = - 5;
		addChild(ball);
		ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownBall);
		addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	
	private function onEnterFrame(event:Event):void {
		vy += gravity;
		ball.x += vx;
		ball.y += vy;
		var left:Number = 0;
		var right:Number = stage.stageWidth;
		var top:Number = 0;
		var bottom:Number = stage.stageHeight;\
		
		if (ball.x + ball.radius &gt; right) {
			ball.x = right - ball.radius;
			vx *= bounce;
		}
		else if (ball.x - ball.radius &lt; left) {
			ball.x = left + ball.radius;
			vx *= bounce;
		}
		if (ball.y + ball.radius &gt; bottom) {
			ball.y = bottom - ball.radius;
			vy *= bounce;
		}
		else if (ball.y - ball.radius &lt; top) {
			ball.y = top + ball.radius;
			vy *= bounce;
		}
	}
	
	private function onMouseDowsnBall(event:MouseEvent):void {
		ball.addEventListener(MouseEvent.MOUSE_UP, onMouseUpBall);
		ball.startDrag();
		removeEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	
	private function onMouseUpBall(event:MouseEvent):void {
		stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpBall);
		ball.stopDrag();
		addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
}

```

}

Thanks.
