首先启动flash,我使用的是Flash 8,然后新建立flash文档,然后按Ctrl J修改文档属性。
按Ctrl F8新建立一个影片剪辑元件,名字是Fragment,然后绘制一个白色的圆,至于大小都任意能够。
返回到主场景中,选择第一帧,输入下面代码。
/* 定义四个全局变量,定义位置 */ _global.gLEFT = 0; _global.gTOP = 0; _global.gRIGHT = Stage.width; _global.gBOTTOM = Stage.height; /* 5个变量定义元件的速度、最大、最小、数量*/ var maxSpeed:Number = 25; var minSize:Number = 4; var maxSize:Number = 10; var minFragments:Number = 50; var maxFragments:Number = 150; /* 在最大和最小之间返回一个数的函数 */ function randRange(min:Number, max:Number):Number { var randomNum:Number = Math.floor(Math.random() * (max - min 1)) min; return randomNum; } /* 主程式片段 */ onMouseDown = function():Void { var totalFragments:Number = randRange(minFragments, maxFragments); var fragment_mc:MovieClip; var depth:Number = this.getNextHighestDepth(); for (var i:Number = 0; i < totalFragments; i , depth ) { fragment_mc = attachMovie("Fragment", "fragment" depth, depth); fragment_mc._x = _xmouse; fragment_mc._y = _ymouse; fragment_mc._width = fragment_mc._height = randRange(minSize, maxSize); while(!fragment_mc.speedX) { fragment_mc.speedX = randRange(-maxSpeed, maxSpeed); } while(!fragment_mc.speedY) { fragment_mc.speedY = randRange(-maxSpeed, maxSpeed); } fragment_mc._alpha = randRange(10, 100); fragment_mc.cacheAsBitmap = true; fragment_mc.onEnterFrame = function():Void { this._x = this.speedX; this._y = this.speedY; if (this._x < gLEFT || this._x > gRIGHT || this._y < gTOP || this._y > gBOTTOM) { this.removeMovieClip(); } }; } }; |
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有