simple square Shapes animation
♥2 |
Line 47 |
Modified 2015-06-05 06:04:40 |
MIT License
archived:2017-03-20 04:31:55
ActionScript3 source code
/**
* Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/g4Lo
*/
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
public class FlashTest extends Sprite {
private var oldSchoolMC:MovieClip;
public function FlashTest() {
// write as3 code here..
oldSchoolMC = new MovieClip();
addChild(oldSchoolMC);
oldSchoolMC.x = 150;
oldSchoolMC.y = 150;
oldSchoolMC.buttonMode = true;
addFrames();
//oldSchoolMC.addEventListener(Event.ENTER_FRAME, onEnterFrame);
oldSchoolMC.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void{
if(oldSchoolMC.hasEventListener(Event.ENTER_FRAME)){
oldSchoolMC.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}else{
oldSchoolMC.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
private function addFrames():void {
for (var i:int = 0 ; i < 0xffffff ; i+=100000) {
oldSchoolMC.addChild(genColRect(i));
if (oldSchoolMC.numChildren > 0) {
oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleX = (250 - oldSchoolMC.numChildren) / 250;
oldSchoolMC.getChildAt(oldSchoolMC.numChildren - 1).scaleY = (250 - oldSchoolMC.numChildren) / 250;
}
}
}
private function onEnterFrame(e:Event):void {
for (var i:int = 0 ; i < oldSchoolMC.numChildren ; i++) {
oldSchoolMC.getChildAt(i).rotation += (oldSchoolMC.numChildren - i);
}
}
private function genColRect(col:int = 0xffffff):Shape {
var spr:Shape = new Shape();
spr.graphics.beginFill(col);
spr.graphics.drawRect( -50, -50, 100, 100);
spr.graphics.endFill();
return spr;
}
}
}