Acessing root stage.stageWidth

Hi,
So I'm trying to do a simple graph with rollover definitions. I have the graph on one layer in the root along with the definitions. On a hit testing MC I have the following:
var defbox:info = new info();
var mcName  = this.name;
var xPos =  (MovieClip(parent).stage.stageWidth)/2;
var yPos =  (MovieClip(parent).stage.stageHeight)/2;
this.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
function mouse_over(event:MouseEvent):void {
     this.removeEventListener(MouseEvent.MOUSE_OVER, mouse_over);
     this.addEventListener(MouseEvent.MOUSE_OUT, mouse_out);
     this.addChild(defbox);
     defbox.x = xPos-350;
     defbox.y = yPos-350;
     defbox.alpha = .95;
     defbox.title.title.text = MovieClip(parent).titles[mcName];
     defbox.def.text = MovieClip(parent).definitions[mcName];
     defbox.def.autoSize = "center";
     defbox.body.height = defbox.def.height + 25;
     defbox.title.y = defbox.body.y -8;
function mouse_out(event:MouseEvent):void {
     this.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
     this.removeEventListener(MouseEvent.MOUSE_OUT, mouse_out);
     this.removeChild(defbox);
The problem is that the loaded MC namely, defbox is does not appear at stage.width/2 (or height). It appears to be loading somewhere relative to the hit tester (the mc where the defbox mc is being loaded). I can't seem to access the root stage. I'm pretty sure that all the MCs registry points are normal. Any suggestions? Thanks.

use:var defbox:info = new info();
var mcName  = this.name;
var pt:Point = new Point(stage.stageWidth)/2,stage.stageHeight)/2);
var newpt:Point = this.globalToLocal(pt);
defbox.x=newpt.x;
defbox.y=newpt.y;
this.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
function mouse_over(event:MouseEvent):void {
     this.removeEventListener(MouseEvent.MOUSE_OVER, mouse_over);
     this.addEventListener(MouseEvent.MOUSE_OUT, mouse_out);
     this.addChild(defbox);
     defbox.x = xPos-350;
     defbox.y = yPos-350;
     defbox.alpha = .95;
     defbox.title.title.text = MovieClip(parent).titles[mcName];
     defbox.def.text = MovieClip(parent).definitions[mcName];
     defbox.def.autoSize = "center";
     defbox.body.height = defbox.def.height + 25;
     defbox.title.y = defbox.body.y -8;
function mouse_out(event:MouseEvent):void {
     this.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
     this.removeEventListener(MouseEvent.MOUSE_OUT, mouse_out);
     this.removeChild(defbox);
The problem is that the loaded MC namely, defbox is does not appear at stage.width/2 (or height). It appears to be loading somewhere relative to the hit tester (the mc where the defbox mc is being loaded). I can't seem to access the root stage. I'm pretty sure that all the MCs registry points are normal. Any suggestions? Thanks.

Similar Messages

  • Stage.stageWidth in Percent not Pixels

    Hi All,
    I am trying to set masks and other component positions in relation to Stage size.
    AS3 CS5
    I trace stage.stageWidth on a 800x600 pixel stage and I get - 100
    My stage will scale within a Director piece.
    Is this a bug? Modal condition? Releated to scaling??
    Thanks,
    Jim

    Now this is interesting.
    stop();
    trace ("The Stage width is " + root.stage.stageWidth);
    trace ("The Stage height is " + this.stage.stageHeight);
    var temp:Number = new Number();
    temp = stage.width;
    trace(temp);
    The first time I run the swf-compile (ctrl-Enter) - It Output the following:
    Page1 is now loaded
    The Stage width is 100
    The Stage height is 100
    0
    While the SWF is still selected (being viewed) I hit ctrl-Enter again and I get this add to it:
    Page1 is now loaded
    The Stage width is 1874
    The Stage height is 763
    0
    This is the size of my stage window in the FLA development window.
    I drag it out of the projects bar to be an independent window and it gives me what I expected:
    Page1 is now loaded
    The Stage width is 800
    The Stage height is 600
    0
    Note I can make the window any size and I get the same right -expected - answer, except when it overlaps other Flash dev. window objects or a display border.
    food for thought,
    Jim

  • Viewing Flash Applications on a Mac: stage.stageWidth/stage.stageHeight Return 0 in Firefox/IE

    I am using SWFOBJECT to embed my flash content.
    I have been worried about stage.stageWidth and stage.stageHeight returning 0 in Firefox/Internet Explorer; this problem is referred to in question #21 on the SWFOBJECT FAQ (http://code.google.com/p/swfobject/wiki/faq).
    I have been told that this problem is particularly prevelant on Macs.
    The SWFOBJECT FAQ (question 21) indirectly suggests that this problem does not occur with static publishing.  Is this correct?  Is it still advisable to implement a solution to this stageWidth/stageHeight problem, even if you are using static publishing?
    Thank you.

    Bug 3637793
    https://bugbase.adobe.com/index.cfm?event=bug&id=3637793

  • AS3 Preloader matching stage.stageWidth (simple)

    Hello,
    Experimenting with Flash as usual.
    Preloader's are always something that have caused me trouble.
    Here's what I typically use for a timeline based preloader in AS3:
    this.addEventListener(Event.ENTER_FRAME, loading);
    function loading(e:Event):void {
    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;
    loadBar.scaleX = loaded/total;
    loaderText.text = Math.floor((loaded/total)*100)+ "%"; (if percentage text is wanted)
    if (total == loaded) {
    gotoAndPlay(3);
    this.removeEventListener(Event.ENTER_FRAME, loading);
    This works perfectly well, but isn't that pleasing aesthetically.
    I'm really interested in a preloader that loads right across the stage however - regardless of if the stage is resized.
    I should imagine it'll involve implementing = Math.round(stage.stageWidth); at some point?
    If anybody knows how this is achieved, through actionscript, in the timeline, I'd really appreciate the support
    Thanks a lot!

    I haven't been able to make this work straight away with this code:
    var lbW:Number
    var stageW:Number
    var ratioNum:Number
    resizeF(null);
    stage.addEventListener(Event.RESIZE,resizeF);
    function resizeF(e:Event){
    lbW = loadBar.width
    stageW = stage.stageWidth
    ratioNum = stageW/lbW;
    this.addEventListener(Event.ENTER_FRAME, loading);
    function loading(e:Event):void {
    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;
    loadBar.scaleX = ratioNum*loaded/total;
    if (total == loaded) {
    gotoAndPlay(2);
    this.removeEventListener(Event.ENTER_FRAME, loading);
    But I shall explore and try and fix it.
    Thanks so much for your time and expertise!
    Really do appreciate it!

  • On Firefox stage.stageWidth stage.stageHeight return wrong values

    Hello,
    I have a problem on firefox windows 8, stage.stageWidth and stage.stageHeight return wrong values,
    swfobject.embedSWF("mySwf.swf", "mySwf", "500", "500", "14.0.0","expressInstall.swf", flashvars, params, attributes);
    on ie, Chrome stage.stageWidth and stage.stageHeight return 500
    on iFirefox stage.stageWidth and stage.stageHeight return 750 and my animation is smaller (66%)
    Thanks

    In order to target iPhone 5 you need to use AIR 3.5 beta or AIR 3.4
    pointing to iOS 6 SDK. Be sure to include the [email protected] to
    trigger the iPhone 5 size. In other words, the app has to be built
    targeting the iOS 6 SDK and have the new default png to trigger the full
    size on the iPhone 5.
    AIR 3.5 beta includes the bits that to target iOS 6 SDK, but you can
    target iOS 6 with AIR 3.4 by using the external SDK path in the package
    ANE prompt in FB 4.6
    http://labs.adobe.com
    iBrent

  • Stage.stageWidth and some browsers

    Has anyone else encountered this? When I program banner ads, I use a variable to calculate the center of the banner, something like:
    var MiddleX = stage.stageWidth/2; //If stage is 300 pixels wide MiddleX would be 150
    I then use that variable to position text dead center, something like:
    mcText.x = MiddleX;
    What I have discovered is that some browsers don't care for this. So instead of centering the text they position it at 0. The quick fix was to just put in a number rather than have it calculate.
    I don't think the code is flawed. Just wondering why some browsers hiccup on this code. It seems pretty basic.

    there could be some issues with scaling unless you assign the scaleMode to noScale.

  • Cannot access Stage.stageWidth

    with this:
    trace(Stage.stageWidth)
    i get this error:
    1119: Access of possibly undefined property stageWidth
    through a reference with static type Class.

    the stage class is accessible through any object on the
    stage.
    say you have a movieclip on the stage named myMC. Then
    accessing stage width is done like this...
    MovieClip(myMC).stage.stageWidth;
    In AS3, Flash no longer cares about the depth of loaded
    movies. There is only one stage in AS3 so accessing the stage from
    an external movie loaded in is the same as accessing a movie clip
    you place on the stage from your library.

  • Add TextLayout Component to root stage

    Hi Guys,
    do you know why this code doesn't work? The code is in the main timeline, first fotogramme. I have TextLayout in my library.
    import fl.controls.*;
    var tt:TextLayout = new TextLayout();
    this.addChild(tt);
    tt.x = 0;
    tt.y = 0;
    tt.width = 200;
    tt.height = 200;
    Get this error:
    ReferenceError: Error #1065: Variable TextLayout is not defined.
    ReferenceError: Error #1065: Variable ComponentShim is not defined.

    To use TLF with Flash CS4, you need to use the original TLF version that was posted together with the Flash component. The Flash component has not been updated to work with the newer TLF builds. Sorry!

  • Having Problems with removing an addEventListener

    Greetings Adobe community,
    Im currently having a problem with my flash assignment,
    I have a:   this.addEventListener(Event.ENTER_FRAME, onPanSpace);
    who is causing errors when I go to the next frame:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
              at Confabulation_fla::mc2_3/onPanSpace()[Confabulation_fla.mc2_3::frame1:13]
    I would like to remove this addEventListener when I go to the next frame(which is by clicking on a door) but to be honest, I have no clue how.
    So I ask you "How do I remove this addEventListener on my next frame?"
    Kind Regards
    Notnao

    function addTheListeners():void {
         addEventListener(Event.ENTER_FRAME, onPanSpace);
         addEventListener(Event.REMOVED_FROM_STAGE, cleanUp);
    var snelheidNum:Number = 0.5;
    var snelheid:Number = 0;
    var MouseIsLinks:Boolean;
    function onPanSpace(e:Event):void
              var afstand:Number = Math.round(this.x - this.bg1.x);
              var percentage:Number = Math.floor((100 * afstand) / (this.bg1.width - root.stage.stageWidth));
              snelheid = -((root.stage.mouseX - (root.stage.stageWidth / 2))/110)/snelheidNum;
              if(root.stage.mouseX < (root.stage.stageWidth / 2)) { MouseIsLinks = true }
              if(root.stage.mouseX > (root.stage.stageWidth / 2)) { MouseIsLinks = false }
              if( (percentage < (1 - 100) && MouseIsLinks) || (percentage > (80 - 100) && !MouseIsLinks)) {snelheid = 0;}
              this.bg1.x += (snelheid / 1);
    function cleanUp(e:Event):void {
         removeEventListener(Event.ENTER_FRAME, onPanSpace);
         removeEventListener(Event.REMOVED_FROM_STAGE, cleanUp);
    //this.addEventListener(Event.ENTER_FRAME, onPanSpace);
    stop();
    This is what I got now, It removes the addeventListeners and I have no problems at the next frame but now my first frame doesnt have the onPanspace effect.

  • Nested MC's position regarding stage

    Arrgh! Here it is.
    I have a master MC that's added to the stage via
    addChild(p2_mc).
    Inside that p2_mc, i have others MC'S (added to the stage
    manually, not via addChild).
    One of them is instanced fond_mc
    I want to position that fond_mc in the middle of the stage
    using that line of code WHEN the stage is resized. Obviously, the
    following line is into the resize function:
    fond_mc.x = stage.stageWidth/2;
    I works but returning faulty results because it uses left
    corner of the mc instead of registration point, which is top and
    center.
    I tried all math formula i could think of to no results.
    Keeps positionning the fond_mc wrongly.
    I know this is related to registration OR stage measurement.
    Is there a way to reset stage.stageWidth values INSIDE the
    resize function?
    Thanks!

    ahhh. so then when the container is brought to the stage it
    *is* being aligned at 0, 0 correct?
    ...> nope, it is aligned when created with this
    var p2_mc:MovieClip = new P2;
    MovieClip(root).addChild(p2_mc);
    p2_mc.x = stage.stageWidth/2;
    p2_mc.y = 0;
    The problem is WHEN i resizes, the children clips INSIDE the
    container has no references that i can understands.
    As i said, when i add this inside the resize function at root
    level, it works:
    p2_mc.x = stage.stageWidth/2;
    because in my test files, p2_mc is added BEFORE the resize
    function kicks off. And the childs move accordingly around the
    stage.
    But in my project file, p2_mc is dynamically created only
    when the user press a button. Therefore, the resize function isnt
    seeing p2_mc first hands and gives me error.
    I want to avoid adding ALL of my navigation clips to the
    stage on frame 2 (after the preloader) and BEFORE resize function
    is run. That would work i guess, but ill have to manually rendering
    them visible or not.

  • Scrolling menu panel scrolls whole stage content, how to restrict EventListener to mouse.y 90 ?

    hei folks,
    the snippet attached works great, it scrolls (parallaxed) my
    menu horizontally left to right, when I move my mouse horizontally
    over the menu panel.
    But if I klick on the menu buttons nested inside this menu
    panel, they do appear, unfortunatly does the content also scrolls
    horizontally if I move to the menu to select another Button :(
    I am not able to modify this code-snippet from user kglad,
    that it doesnt scroll the whole stage but the panel itself.
    Can someone please give me a hint, on this menu I have spent
    hours, bloody learn curve.
    source of this code: user
    kglad - thank you very much kglad btw.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=665&threadid =1324923&highlight_key=y&keyword1=scroll#4807043

    thank you very much, even though the following problem
    remains, I'm sure that there is just a minor misconception of mine:
    this mc is horizontally scrolling a menu if the mousesY is 90
    and 250 (its row of buttons is longer than the stage) the buttons
    and their common timeline are nested inside the front_mc. if I go
    sidewards over the menu and its scrolling left/right & I hit a
    button the content is drawn, but when I head back to the menu and
    it's scrolling, so does the drawn content analogue to the menu
    (synched).
    I must have organized it wrong.
    front_mc.addEventListener(MouseEvent.MOUSE_MOVE,f);
    var t:Timer=new Timer(30,0);
    t.addEventListener(TimerEvent.TIMER,moveF);
    function f(e:MouseEvent) {
    if(root.mouseY > 90 && root.mouseY < 250) {
    t.start(); }
    else {
    t.stop();
    var speed:Number = .9;
    function moveF(e:TimerEvent) {
    front_mc.x
    =speed*front_mc.x+(1-speed)*(stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidt h;
    back_mc.x =
    speed*back_mc.x+(1-speed)*(stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth;
    if (Math.abs(front_mc.x-
    (stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidth)<1
    Math.abs(back_mc.x-(stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth)<1)
    front_mc.x =
    (stage.stageWidth-front_mc.width)*root.mouseX/stage.stageWidth;
    back_mc.x =
    (stage.stageWidth-back_mc.width)*root.mouseX/stage.stageWidth;
    t.stop();
    e.updateAfterEvent();

  • Why does width=stage.fullScreenWidth; function inproperly ?

    Peace be upon you
    I have a timebar in my flash android app (testing sample), that I want to extend horizantally to the full screen width (in all phones and tablets).
    I tried many many things, visited all programming websites .. and I made use of this useful article Supporting the multiple screen sizes of multiple devices in Adobe AIR | Adobe Developer Connection
    and tested them on many devices but still, something is still wrong!
    when I use
    1- Object(root).bar.width =stage.fullScreenWidth ;                      // the timebar fits the width but animates LATE
    2- Object(root).bar.width =stage.stageWidth;                              // the timebar fits the width but animates LATE
    3- Object(root).bar.width =stage.width;                                        // the timebar doesn't fit the width but animates rightaway!
    4- Object(root).bar.width =Capabilities.screenResolutionX;        // the timebar fits the width but animates LATE
    here the sample:testing sample.fla - Google Drive
    can someone tell me why is the latency in the timebar animation !??
    I want my timebar to be in it's original speed (fast) and have it to fit the screen width in any size ..
    Thanks in advance ..

    I tried it without Object(root) and it still didn't work .. though my code isn't nested at all .. no errors to .. it's just a latency and no fit for width
    here's a screenshot from my phone , you see the second bar starts rightaway!
    but the other ones start late .. but they all finish in the same time!!
    why??? they also won't fit the phone's screen width :/
    i coded them in this order
    1- bar1.width =stage.fullScreenWidth ;            
    2- bar2.width =stage.stageWidth;                    
    3- bar3.width =stage.width;                             
    4- bar4.width =Capabilities.screenResolutionX;       
    do you have a solution??
    sorry for bothering you with this ,,

  • Problem with root and constructors

    hello guys,
    i have serious problem, its 2 days i am trying to do something about it,
    i have some object inside object inside another object,
    if in their constructors i write:
    MovieClip(root).someVar
    (or function)
    its not working!
    it works only i regular functions,
    i cant even call a egular function from the constructor,
    please help my guys, i really need this!
    thanks alot!

    function YourDisplayObjectClass(){
    // this is the contructor
    // trying to reference MovieClip(root) or stage will trigger a null ref error
    // because YourDisplayObjectClass instance isn't added to the stage, yet
    this.addEventListener(Event.ADDED_TO_STAGE,init);
    private function init():void{
    // from here you can reference displaylist items.
    trace(MovieClip(root),stage);

  • Stage Height/Width Issue

    I am writing a piece of code that basically says if a certain MC reaches a ypos of -50 to perform a set of actions:
    EXAMPLE CODE
    if(balloon.clip.y <= topBounds)
                    //actions here
    But for some reason it wasn't recognizing when the MC would reach the specified ypos. I did a simple trace statement of the stage height and width because I suspected something was off with the script reading x and y positions. And sure enough the output of the trace did not correctly match what my actual stage size was set to in my fla.
    trace(stage.stageHeight); This traced 798
    trace(stage.stageWidth); This traced 1440
    While my actual stage is set to 550x400.
    Am I missing something here? I also traced the ypos of the moving MC and the trace output positions that were nowhere near the actual y positions of the MC as it moved. Ironically though, the external class file to this object recognizes the correct x and y positions when I call the function from the .as file. Only when I try to call the function from the fla file do I run into this issue of incorrect x and y positions.
    Any help? Thanks

    Below is my code for my as class file and the code being called from the stage within the fla file. The issue I am having is with the conditional statement in the fla code, I have highlighted it in bold and italics. The ypos of the MC is not registering at -50 when clearly the object has a y position of -50. Something seems messed up with the x and y positions of the clip on the stage because the y position traced to teh output panel is nowhere close to the actual y position of the clip on the stage as it moves.
    .as file code
    package
        import flash.display.Stage;
        import flash.display.*;
        import flash.display.DisplayObjectContainer;
         import flash.display.MovieClip;   
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        import flash.events.Event;
            public class Balloon
                    public var clip: MovieClip;
                    public var xVel: Number = 0;
                    public var yVel: Number = 0;
                    public var upwardForce:    Number = 0; // applies to y value
                    public var shrink: Number = 1;
                    public var fade: Number = 0;
                    public var topBounds: Number = -50
                    public function Balloon(symbol:Class, target:DisplayObjectContainer, xpos:Number, ypos:Number, size:Number)
                            clip=new symbol();
                            target.addChild(clip);
                            clip.x = xpos;
                            clip.y = ypos;
                            clip.scaleX=clip.scaleY=size;
                        } // end Balloon constructor function
                    public function moveObject():void
                            clip.x += xVel;
                            clip.y += yVel;
                            yVel -= upwardForce;
                            clip.scaleX *= shrink;
                            clip.scaleY *= shrink;
                            clip.alpha -= fade;
                      }//end moveObject function
                    public function removeObject():void
                            clip.parent.removeChild(clip);
                        }// remove balloon from the stage
                } // end Balloon class
    }// end package
    code inside fla
    var balloonArray:Array = new Array();
    stage.addEventListener(Event.ENTER_FRAME, startBalloons)
    function startBalloons(evt:Event):void
            var balloon: Balloon; // referencing our Balloon Class
            for(var i:int=0; i<balloonArray.length; i++)
                    balloonArray[i].moveObject(); // calls moveObject function thats in the class file
            balloon = new Balloon(hotAirBalloon, this, randomRange(200, 400), randomRange(400, 550), randomRange(0.3, 1));
            balloon.xVel = -3; 
            balloon.yVel = -4;
            balloon.shrink = 0.9999;
            balloon.fade = 0.000011;
            balloon.upwardForce = .005
            balloonArray.push(balloon);
            if(balloonArray.length>randomRange(1, 5))//creates only 3 balloons and removes all others created from th array
                   balloon.removeObject();
        if(balloon.clip.y <= -50)
           trace("balloon has reached the top"
            var balloonTimer:Timer = new Timer(randomRange(25,45)*1000, 1);
            balloonTimer.addEventListener(TimerEvent.TIMER,timerFinished);
            balloonTimer.start();
            function timerFinished(event:TimerEvent):void
                        trace("time's up")
                        balloonTimer.stop();
                        balloon.clip.x = Math.random() * (400-200) + 200; // give random x pos to start from
                        balloon.clip.y = Math.random() * (1000-400) + 400; // give random y pos to start from
                        balloon.clip.scaleX = balloon.clip.scaleY = Math.random() * (1-0.3) + 0.3;
                        balloon.clip.alpha=1;
            } // end startBalloons function
        function randomRange(offset:Number, maxValue:Number) // generic function for randomizing object properties
                return Math.random() * (maxValue-offset) + offset

  • Stage dimensions(size) in Flash CS4 (AS3)

    Hi again,
    I need to know how to get the dimensions of my stage (x,y), BUT only the stage and not all the objects that might continue off the stage included.
    For example :
         My stage is 400 x 550.
         I want to get 400 and 550 returned.
    Thank you for any help and tips!

    You can use:
    var nW:Number = stage.stageWidth;
    var nH:Number = stage.stageHeight;

Maybe you are looking for