开发者

swap different colour rectangle in movieclip

开发者 https://www.devze.com 2023-01-21 18:41 出处:网络
I am trying to create a开发者_如何学编程 basic example. Using frames i know how to do that but i want to know how this can be done using action script 3.

I am trying to create a开发者_如何学编程 basic example. Using frames i know how to do that but i want to know how this can be done using action script 3.

Using frame:

A movieclip in which there are 6 frames

  • Red rectangle in first 3 frames

  • Blue rectangle in last 3 frames

Can someone please tell me how to do this using AS3?


There are many ways to achieve this, you could use Timer , Tween etc... here's a basic example.

 var _count:int;
 var red:Boolean = true;
 var rectangle:Sprite = new Sprite();
 var rectWidth:int = 300;
 var rectHeight:int = 120;

 addChild( rectangle );

 addEventListener( Event.ENTER_FRAME , enterFrameListener );

 function enterFrameListener(event:Event):void
 {
     if( _count > 0 && _count % 3 == 0 )
        colorChange();

     _count++;
 }

 function colorChange():void
 {
    var color:uint; 

    if( red )  
       color = 0x990000;
     else
       color = 0xfadd00;

    with( rectangle.graphics )
    {
        clear(); 
        beginFill(color);
        drawRect( 0 , 0 , rectWidth , rectHeight );
        endFill();

    }

     red = !red;
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消