A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Resizing a container based on it contents.

Hybrid View

  1. #1

    Resizing a container based on it contents.

    Hey there,

    So I have a container movie clip which will be holding multiple container movie clips. I want to set the size of the main container based on the size of is contents. I was hoping the size could toggle. Here is what Im doing

    /*function newvid(event:MouseEvent) {
    trace("you clicked me");
    var loadit = new Loader();
    loadit.load(new URLRequest("swf001.swf"));
    my_mc.addEventListener(MouseEvent.MOUSE_DOWN, newvid);*/
    /*function newvid2(event:MouseEvent) {
    trace("2 you clicked me");
    var loadit2 = new Loader();
    loadit2.load(new URLRequest("swf002.swf"));
    my_mc2.addEventListener(MouseEvent.MOUSE_DOWN, newvid2);
    /*function newvid3(event:MouseEvent) {
    trace("3 you clicked me");
    var loadit3 = new Loader();
    loadit3.load(new URLRequest("swf003.swf"));
    my_mc3.addEventListener(MouseEvent.MOUSE_DOWN, newvid3);*/
    function killParticle(event:Event):void{
    clipHolder.hold02.height = 0;
    my_mc2.addEventListener(MouseEvent.MOUSE_DOWN, killParticle);
    clipHolder.height = clipHolder.hold01.content + clipHolder.hold02.content + clipHolder.hold03.content ;
    clipHolder.x = 0;
    var request:URLRequest = new URLRequest("swf001.swf");
    var loader:Loader = new Loader();
    var request2:URLRequest = new URLRequest("swf002.swf");
    var loader2:Loader = new Loader();
    var request3:URLRequest = new URLRequest("swf003.swf");
    var loader3:Loader = new Loader();
    Any clues on how to achieve this ? Any help would be great.
    billy nugz is online now Report Post Edit/Delete Message

  2. #2
    Multitouch Aficionado
    Join Date
    Mar 2006
    You don't need to manually set the height - just position the elements properly and the height will match.

    If you are trying to make a background that is always the right size, try adding this to your holding Sprite's class:

    override public function addChild(child:DisplayObject):void{
         var w:uint = //calculate your width here
         var h:uint = //calculate your height here
         with (_backgroundShape.graphics){ // you must define _backgroundShape and add it to your display list earlier
              beginFill(0xAABBCC); // replace this color
              drawRect(0, 0, w, h);

  3. #3
    I need the hieght to resize depending on the size of the movieclips within it so say if I click a button and hold2 gets set to zero the container will shink Does that make sense Maybe I should post the fla?

  4. #4
    Multitouch Aficionado
    Join Date
    Mar 2006
    You're really not changing the height - you're repositioning the clips. I would try this:

    In your child Classes:

    import flash.events.Event;
    override public function set height(value:Number):void{
         dispatchEvent(new Event(Event.RESIZE, true));
         super.height = value;
    And in your container Class:
    import flash.events.Event;
         //Put this in your constructor
         addEventListener(Event.RESIZE, repositionElements);
    private function repositionElements(event:Event = null){
         //your positioning code goes here.

  5. #5
    Im lost. Here is my fla maybe you can see what Im doing wrong.

    Thanks for all your help on this one man.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center