Skip to main content
March 30, 2012
Question

How to Edit shape Dynamically

  • March 30, 2012
  • 1 reply
  • 687 views

Hi All,

I have one doubt in as3..

I have one Movieclip which contains one shape. I want to increase my Movieclip size dynamically. I increased my Movieclip size but it affects my movieclip effects.

So i want to increase my shape size which is there inside movieclip..

This topic has been closed for replies.

1 reply

_spoboyle
Inspiring
March 30, 2012

when you say increase size do you mean you increased the width and height?

try increasing the scaleX and scaleY properties instead

March 30, 2012

Thanks for ur reply..

scaleX ll increase my width..But i want to increase my movieclip width without any problem..

I gave some drop shadow gradient effect to my movieclip..if i increase my MC width na, it ll disturb Movieclip effects.

I want to increase my MC width with same effects.

is there any chance to go inside movieclip and change width of that shape and then apply effects like that...im not sure..

_spoboyle
Inspiring
March 30, 2012

Sorry It's not entirely clear to me what you are after.

you want to be able to change the size of a MovieClip with it's width/height properties and that to affect the size of it's children?

you can create a subclass of MovieClip and override the set width and height function to adjust the size of the shape.

However in these functions how do you want to adjust the size of the shape? is scaling enough? If not you will have to redraw the shape depending on the new size of the movieclip.

If you cna be a bit mroe clear on exactly what you are trying to achieve I can probably be a bit more helpful

below is a demo i knocked up in case it sheds some light on what I was talking about

Main2.as

package

{

          import flash.display.Bitmap;

          import flash.display.BitmapData;

          import flash.display.Sprite;

          import flash.events.Event;

          import flash.events.KeyboardEvent;

          import flash.ui.Keyboard;

 

          public class Main2 extends Sprite

          {

                    private var moveiClip:MyMovieClip;

 

                    public function Main2():void

                    {

                              if (stage)

                              {

                                        init();

                              }

                              else

                              {

                                        addEventListener(Event.ADDED_TO_STAGE, init);

                              }

                    }

 

                    public function init(e:Event = null):void

                    {

                              removeEventListener(Event.ADDED_TO_STAGE, init);

 

                              moveiClip = new MyMovieClip();

                              addChild(moveiClip);

 

                              stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

                    }

 

                    private function onKeyDown(e:KeyboardEvent):void

                    {

                              trace("code: " + e.keyCode);

 

                              switch (e.keyCode)

                              {

                                        case Keyboard.UP:

                                                  moveiClip.height -= 20;

                                                  break;

 

                                        case Keyboard.DOWN:

                                                  moveiClip.height += 20;

                                                  break;

 

                                        case Keyboard.LEFT:

                                                  moveiClip.width -= 20;

                                                  break;

 

                                        case Keyboard.RIGHT:

                                                  moveiClip.width += 20;

                                                  break;

                              }

                    }

          }

}

MyMovieClip.as

package 

{

          import flash.display.MovieClip;

          import flash.display.Shape;

          import flash.filters.DropShadowFilter;

 

          /**

           * ...

           * @author steven O'Boyle

           */

          public class MyMovieClip extends MovieClip

          {

                    private var shape:Shape;

 

                    public function MyMovieClip()

                    {

                              shape = new Shape();

                              shape.graphics.lineStyle(3, 0xff0000);

                              shape.graphics.drawRect(0, 0, 100, 100);

                              shape.x = 100;

                              shape.y = 60;

                              addChild(shape);

 

                              filters = [new DropShadowFilter()];

                    }

 

                    override public function set width(value:Number):void

                    {

                              shape.scaleX = value / width;

                              super.width = value;

                    }

 

                    override public function set height(value:Number):void

                    {

                              shape.scaleY = value / height;

 

                              super.height = value;

                    }

 

          }

}