3

This seems like it would be a really easy thing to do, but its been giving me all kinds of headaches. I have a movieclip that is a gallery, It's linked to be called from AS when a button is clicked. When an image in the gallery is clicked, It fades in using the Tween class and is supposed to be centered in the main stage, but its centering to the movieClip instead.

Here is the code:

//Centers and places image right ondo the display board
function fullLoaded(e:Event):void {
    var myFull:Loader = Loader(e.target.loader);
    addChild(myFull);

    //positioning
    myFull.x = (stage.stageWidth - myFull.width) / 2;
    myFull.y = (stage.stageHeight - myFull.height) /2;

    //register the remove function
    myFull.addEventListener(MouseEvent.CLICK, removeFull);

    new Tween(myFull, "alpha", Strong.easeInOut,0,1,0.5,true);
}

I have tried all of these combinations to no avail:

MovieClip(root).stage.stageWidth  
root.stage.stageWidth  
parent.stage.stageWidth

None of these place the image in the right spot.

2
  • Hi, Have you checked the stage.align propertie ?
    – OXMO456
    May 7, 2009 at 9:23
  • Yea, I've tried that too, without success :( May 7, 2009 at 9:35

2 Answers 2

4

Set these this property to make your stage have it's origo (0x0) in the top left:

stage.align = StageAlign.TOP_LEFT;

And this to make the stage stay the same scale as the window changes size:

stage.scaleMode = StageScaleMode.NO_SCALE;

Then you will need to wait until your image is loaded before you align it, since it won't have a width before then. I would also recommend listening for Event.RESIZE on the stage, this is fired whenever the size changes.

Assuming all that your current code should work fine!

myFull.x = (stage.stageWidth - myFull.width) / 2;
myFull.y = (stage.stageHeight - myFull.height) /2;
3
  • It doesnt work though, because that returns the size of the containing movieclip, not the main stage! :( May 7, 2009 at 18:36
  • stage.stageWidth gives the stages width i'm sure of it. If you're getting strange values try adding the listeners.
    – grapefrukt
    May 7, 2009 at 20:22
  • also, the myFull position is obviously related to whatever the x position it parent has.
    – grapefrukt
    May 7, 2009 at 20:41
0

MovieClip(root).addChild(myFull); don't forget to do the same to removeChild

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.