开发者

Modify multiple movieclips as one

开发者 https://www.devze.com 2023-01-23 18:33 出处:网络
Is there any way to move or scale a bunch of m开发者_运维知识库ovieclips on the stage as one, without putting them inside of another movieclip?

Is there any way to move or scale a bunch of m开发者_运维知识库ovieclips on the stage as one, without putting them inside of another movieclip?

Thanx :)


Edit:

If you're listening to a resize event, there are a few properties that you can use, I assume that your stage.scaleMode property is set to NO_SCALE...

You could set a ratio of 1 by setting your maximum dimensions value to the Capabilities.screenResolutionX and Capabilities.screenResolutionY , which will give you a user's max screen dimensions. Please note that these dimensions correspond to full screen dimensions, not taking account of the browser toolbar for instance.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html

You can then calculate your movie clips current scale by comparing your current stage width/height with the max settings.

      const MAX_WIDTH:int = Capabilities.screenResolutionX;
      const MAX_HEIGHT:int = Capabilities.screenResolutionY;

      //These values should be updated in your resize event listener
      //For a pure AS3 project, I usually use Javascript functions
      //to get a window dimensions
      var currentWidth;
      var currentHeight;
      var widthScale:Number = currentWidth / MAX_WIDTH; 
      var heightScale:Number = currentHeight / MAX_HEIGHT; 

Finally, wouldn't it be simpler to set your stage.scaleMode property to EXACT_FIT?

End of edit

Put your MovieClips in an Array and loop thru the Array to modify them, if each MovieClip needs a specific modification, create an Array of Objects that will store the MovieClip as well as the modifications parameters.

 var mc1:MovieClip = new MovieClip();
 var mc2:MovieClip = new MovieClip();
 //etc...
 var mcn:MovieClip = new MovieClip();

 // you could also use a Vector
 var mcs:Array = [mc1 , mc2 , .... , mcn];

 var scale:Number = .6;


 for( var i:int ; i < mcs.length ; ++i )
 {
        mcs[i].scaleX = widthScale
        mcs[i].scaleY = heightScale;
 }

If you use a Class for your MovieClips, you would create a specific method to modify them, but you'd still have to loop thru the MovieClips to set the modification

 var mc1:MovieClip = new Example();
 var mc2:MovieClip = new Example();
 //etc...

 public class Example extends MovieClip
 {
       public function modify(params:Object):void
       {
            this.scaleX = params.scaleX;
            this.scaleY = params.scaleY;

            //or for example
            TweenMax.to( this , params.delay , {scaleX:params.scaleX , 
                        scaleY:params.scaleY , ease:params.ease} );

       }
 }

 for( var i:int ; i < mcs.length ; ++i )
        mcs[i].modify({scaleX:.5 , scaleY:.6 , delay:1 , ease:Quad.easeOut});
0

精彩评论

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