Flash actionscript 3.0: Attach a MovieClip from Library dynamically using AS3.0

Attach a MovieClip from Library dynamically using AS3.0

Posted by Sankar.G | Posted in | Posted on 11:03 AM

import flash.utils.getDefinitionByName;
var i:Number;
for(i= 1;i<4;i++)
{
var myCube:Class = getDefinitionByName("Cube" + i) as Class;
var cube:Object = new myCube();
cube.name = "cube" + i;
addChild(DisplayObject(cube));
cube.x = i * 100;
cube.y = i * 100;
cube.addEventListener(MouseEvent.ROLL_OVER,eventfunction);
}
function eventfunction(event:MouseEvent):void
{
var bc=(event.target.name.substr(4));
trace("cube"+bc);
getChildByName("cube"+bc).addEventListener(MouseEvent.MOUSE
_DOWN,fun);
getChildByName("cube"+bc).addEventListener(MouseEvent.MOUSE
_UP,fun1);
}
function fun1(e:Event)
{
var ob=e.target;
ob.stopDrag();
}
function fun(e1:Event)
{
var ob1=e1.target;
ob1.startDrag();
}
create 5 Different Movie Clip in flash and name it as cube1,cube2,cube3,........ and give link name and same cube1,cube2,cube3...... and put this script it will work

Comments (0)