使用动作脚本将子级添加到阶段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用动作脚本将子级添加到阶段相关的知识,希望对你有一定的参考价值。
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 } } }
以上是关于使用动作脚本将子级添加到阶段的主要内容,如果未能解决你的问题,请参考以下文章
JS/w2ui:如何使用 w2ui JavaScript UI 库将子级添加到网格?