Revision: 34985
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 31, 2010 20:09 by youngster
Initial Code
import flash.events.Event; import flash.events.MouseEvent; /*Below events allow the mouse move event only when mouse is down and stop the move event when mouse is up*/ stage.addEventListener(MouseEvent.MOUSE_DOWN,down) function down(event:MouseEvent){ stage.addEventListener(MouseEvent.MOUSE_MOVE,generate) } stage.addEventListener(MouseEvent.MOUSE_UP,up) function up(event:MouseEvent){ stage.removeEventListener(MouseEvent.MOUSE_MOVE,generate) } //**************************************************** /*Actual logic to generate childs, myDot is the instance name of the class Dot*/ /*stage.addEventListener(MouseEvent.MOUSE_MOVE,generate)*/ function generate(event:MouseEvent){ var myDot:Dot=new Dot() addChild(myDot) /*Adding child to stage*/ myDot.x=mouseX myDot.y=mouseY /*To generate random size of the object or child */ myDot.scaleX=myDot.scaleY=Math.random()+.2 /*To generate the random frame numbers */ myDot.gotoAndStop(Math.round(myDot.totalFrames*Math.random())+1) /*To generate random numbers of range equal to the size of stage */ myDot.dx=Math.round(Math.random()*800) myDot.dy=Math.round(Math.random()*600) myDot.addEventListener(Event.ENTER_FRAME,update) } /*Here Function update is an ENTER_FRAME event.This function is executed every mili second*/ function update(event:Event){ event.target.x+=(event.target.dx-event.target.x)/10 event.target.y+=(event.target.dy-event.target.y)/10 /*To decrease the alpha value of the childs */ if(Math.round(event.target.x)==Math.round(event.target.dx)){ if(event.target.alpha>0){ event.target.alpha-=0.5 } } }
Initial URL
Initial Description
Initial Title
Adding child to the stage using action script
Initial Tags
script
Initial Language
ActionScript 3