Skip to main content
August 10, 2011
Answered

position array relative to stage

  • August 10, 2011
  • 1 reply
  • 635 views

Hi There,

Can anyone reccomend a way to position an array containing movie clips relative to the stage? Here's what I was trying...

import flash.display.MovieClip;

var one:MovieClip = new One();
addChild(one);
var two:MovieClip = new Two();
addChild(two);
var three:MovieClip = new Three();
addChild(three);

function initialDisplay(event:Event):void {
     
var myStage:Stage = this.stage;
var swfWidth:int = myStage.stageWidth;
var swfHeight:int = myStage.stageHeight;
var spacing:Number = 10;

var clipArray:Array = [one, two, three];
for (var i:int = 0; i < clipArray.length; i++) {
     clipArray.buttonMode = true;
     clipArray.y = spacing + i * (one.height + spacing);
     clipArray.x = 100;
     }
     clipArray.y = swfHeight - 50;
}

addEventListener(Event.ENTER_FRAME, initialDisplay);

I know clipArray.y refers to the y positoin spacing, but I can't figure out how to tell the entire array to stay 50 pixels from the bottom of the swf doc so that it stays relative to browser size.  I want to do this in an array so that in the future, I can say, whenever clipArray is clicked (i.e. mc one, two or three); remove a child that contains a background animation.

Thanks!

This topic has been closed for replies.
Correct answer kglad

:

rahdwh wrote:

Hi There,

Can anyone reccomend a way to position an array containing movie clips relative to the stage? Here's what I was trying...

import flash.display.MovieClip;

var one:MovieClip = new One();
addChild(one);
var two:MovieClip = new Two();
addChild(two);
var three:MovieClip = new Three();
addChild(three);

function initialDisplay(event:Event):void {
     
var myStage:Stage = this.stage;
var swfWidth:int = myStage.stageWidth;
var swfHeight:int = myStage.stageHeight;
var spacing:Number = 10;

var clipArray:Array = [one, two, three];
for (var i:int = clipArray.length-1; i>=0;i--) {
     clipArray.buttonMode = true;
     clipArray.y = -50+swfHeight-clipArray.length*(one.height+spacing) + i * (one.height + spacing);
     clipArray.x = 100;
     }
}

addEventListener(Event.ENTER_FRAME, initialDisplay);


1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 10, 2011

:

rahdwh wrote:

Hi There,

Can anyone reccomend a way to position an array containing movie clips relative to the stage? Here's what I was trying...

import flash.display.MovieClip;

var one:MovieClip = new One();
addChild(one);
var two:MovieClip = new Two();
addChild(two);
var three:MovieClip = new Three();
addChild(three);

function initialDisplay(event:Event):void {
     
var myStage:Stage = this.stage;
var swfWidth:int = myStage.stageWidth;
var swfHeight:int = myStage.stageHeight;
var spacing:Number = 10;

var clipArray:Array = [one, two, three];
for (var i:int = clipArray.length-1; i>=0;i--) {
     clipArray.buttonMode = true;
     clipArray.y = -50+swfHeight-clipArray.length*(one.height+spacing) + i * (one.height + spacing);
     clipArray.x = 100;
     }
}

addEventListener(Event.ENTER_FRAME, initialDisplay);


August 10, 2011

Thanks again,

I've used that code, only it doesn't keep it fixed at the 50 pixel-from-the-bottom of the stage y position.  Depending on how I drag the window, it is either more or less than 50.  It does appear to be at 50 pixels from the botton when then the file first opens, however...

kglad
Community Expert
Community Expert
August 10, 2011

1.  you shouldn't use an enterframe loop for that, use a stage resize listener and publish your swf for 100%x100% so you stage resizes with the window or

2.  use javascript the externalinterface class to reposition when the window changes size.