A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Dynamic Positioning Only Working After Resize

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    6

    resolved [RESOLVED] Dynamic Positioning Only Working After Resize

    Hey everyone,

    I'm having a really annoying issue here. First of all, I got the following code snippet from: http://blog.soulwire.co.uk/flash/act...ning-part-one/

    Its a dynamic positioning template, basically. Here's my problem: I'm importing docked_icons.swf onto the stage via the holder movie clip (at the end). However, the position is messed up until I resize the window. From there, it's perfect. How do I set the initial position to be correct? I feel like I've tried everything!! Thanks!

    Code:
    // Setup the Stage properties
    Stage.scaleMode = "noScale";
    Stage.align = "TL";
     
    // Create some dummy boxes
    // This is only for the demonstration
     
    var margin:Number = 10;
    var boxSize:Number = 100;
    
    var boxes = [
    		["top", "0x9933cc"],
    		["right", "0x00ff00"],
    		["left", "0x0099ff"],
    		["center", "0xff3399"]];
     
    for (var i = 0; i < boxes.length; i++)
    {
    	var newBox:MovieClip = createEmptyMovieClip (boxes[i][0], getNextHighestDepth ());
     
    	var nameBadge = newBox.createTextField ("test_txt", 1, 0, (boxSize / 2) - 10, boxSize, 10);
    	nameBadge.autoSize = "center";
    	nameBadge.text = boxes[i][0];
    	nameBadge.textColor = 0xffffff;
     
    	with (newBox)
    	{
    		beginFill (boxes[i][1],100);
    		moveTo (0,0);
    		lineTo (boxSize,0);
    		lineTo (boxSize,boxSize);
    		lineTo (0,boxSize);
    		lineTo (0,0);
    		endFill ();
    	}
    }
     
    /*
    	The core function...
    	I keep this separate from the 'onResize'
    	handler so that I can call it at the start
    	to position all of my elements if the screen
    	size has remained the same
    */
    
    function setStage ()
    {
    	var sw:Number = Stage.width;
    	var sh:Number = Stage.height;
    /*
    Rule for Top / Center alignment
    */
    	top._x = sw / 2 - top._width / 2;
    	top._y = margin;
    /*
    Rule for Right / Middle alignment
    */
    	right._x = sw - (right._width + margin);
    	right._y = sh / 2 - right._height / 2;
    /*
    Rule for Bottom / Center alignment
    */
    	holder._x = sw / 2 - holder._width / 2;
    	holder._y = sh - (holder._height + 11 * margin);
    /*
    Rule for Left / Middle alignment
    */
    	left._x = margin;
    	left._y = sh / 2 - left._height / 2;
    /*
    Rule for Center / Middle alignment
    */
    	center._x = sw / 2 - center._width / 2;
    	center._y = sh / 2 - center._height / 2;
    }
     
    // Add a listener
    var stageListener:Object = new Object ();
    Stage.addListener (stageListener);
     
    // When the Stage dimensions change...
    stageListener.onResize = setStage;
     
    // Call our function to set it all up right!
    setStage ();
    
    this.createEmptyMovieClip("holder", 100);
    holder.loadMovie("docked_icons.swf");
    Also, this is Flash 8, AS2.
    Last edited by StickyGlue; 07-07-2009 at 11:29 PM.

  2. #2
    Junior Member
    Join Date
    Aug 2008
    Posts
    6
    Fixed!

    I put the actual dimensions of the swfs I was importing, (instead of holder.width, for example), and it worked!

Tags for this Thread

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