dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: stage center

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    6

    stage center

    Hi

    I have mc1 which I want to align to the center of the stage, in that case my code works:

    Stage.scaleMode = "noScale";
    this.onEnterFrame = function(){
    Stageheight = Stage.height/2
    Stagewidth = Stage.width/2
    mc1._y = Stageheight - (mc1._height/2);
    mc1._x = Stagewidth - (mc1._width/2);
    }

    I used onEnterFrame because I want it to stay in the center even if the stage size changes. For some reason, it stays around the bottom right corner of the stage when the stage is resized. Not sure what I'm doing wrong here.

  2. #2
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    What do you set Stage.align to? If it isn't set the whole movie will be centered as the stage resizes so if you want a movieclip centered on stage you shouldn't need to do anything with it. Unless you move about _root as well.

    When aligning something while the movie is centered on stage you need to take the original stagesize into account as well.

    And if you do need to align something while the movie uses align
    Also it's better to use a listener for Stage.onResize events. That way you'll only be moving the movieclip when it's needed:

    Code:
    Stage.scaleMode = "noScale";
    var myListener = new Object()
    myListener.onResize = function(){
        Stageheight = Stage.height/2
        Stagewidth = Stage.width/2
        mc1._y = Stageheight - (mc1._height/2);
        mc1._x = Stagewidth - (mc1._width/2);
    }
    
    Stage.addListener(myListener)
    /Mirandir

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    6
    Hi
    Thanks for the tip, but it still causes the same problem. Try that script in flash with actionscript 2 and you will see what I mean. When you drag the browser window to expand it, the mc stays in the bottom right corner of the screen. I want it to ALWAYS be in the center, no matter what size of stage. and I only want that mc to be in the center, I have other elements I will align other places...

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