3

I thought this would be straight forward but I'm having trouble repositioning my content. I have a button instance named rollOne, When I roll over the button I want to load an swf object but not on top of the button so I want to find out what the button's width is so I can reposition the dynamically loaded content. I thought rollOne.width would return the width, but it only returns 0 the same goes for height.

Any suggestions would be much appreciated.

rollOne.addEventListener(MouseEvent.MOUSE_OVER, fetchQty);
function fetchQty(event:MouseEvent):void
{
    myContainer.x = (rollOne.x + rollOne.width);
    myContainer.y = (rollOne.y + rollOne.height);
    var img1Request:URLRequest = new URLRequest("8032697883620.swf");
    var img1Loader:Loader = new Loader();
    img1Loader.load(img1Request);
    myContainer.addChild(img1Loader);
    trace(rollOne.width);
}
poke
  • 369,085
  • 72
  • 557
  • 602
SurferJoe
  • 965
  • 1
  • 8
  • 13
  • Nothing wrong with the code here, you would need to show how rollOne is created – PatrickS Nov 27 '11 at 11:10
  • That should work. What happens if you use event.target.width instead of rollOne.width? – Lars Blåsjö Nov 27 '11 at 11:12
  • rollOne is just a button symbol dragged onto the stage and given an instance name of rollOne. – SurferJoe Nov 27 '11 at 11:12
  • event.target.width sends back 0 as well – SurferJoe Nov 27 '11 at 11:13
  • I copied, pasted and reduced your code in Flash CS 5.5 and it perfecly works: `rollOne.addEventListener(MouseEvent.MOUSE_OVER, fetchQty); function fetchQty(event:MouseEvent):void { trace(rollOne.width); }` – AsTheWormTurns Nov 27 '11 at 13:30
  • if you simply trace rollOne [I mean, trace (rollOne)], what's the output? – Sr.Richie Nov 27 '11 at 13:33
  • Does rollOne has content before the 8032697883620.swf is loaded? If it's empty, you may need to wait for complete event handler of the Loader to perform size operations - maybe add a transparent rectangle overlay to your button. – Jason Sturges Nov 27 '11 at 19:12

2 Answers2

2

I assume that rollOne is an instance of SimpleButton or MovieClip If it is a MovieClip make check that the first frame is not empty. If it is a SimpleButton then check that all states are not empty.

You can also make a Class of your own that will ignore the original width and height:

public class MyButton extends SimpleButton
{
    private var _width:Number;
    private var _height:Number;
    public function MyButton(widthInput:Number, heightInput:Number)
    {
        this._width = widthInput;
        this._height = heightInput;
    }

    override public function get width():Number
    {
        return _width;
    }

    override public function get height():Number
    {
        return _height;
    }
}
  • Thank you,The over state of the button was empty because the rectangle's fill was set to none. Make sure that your invisible rollover's fill is not set to none and instead set it's alpha to 0 – SurferJoe Nov 27 '11 at 20:05
-2

In Flash 8 (or ActionScript <=2) you have to use object._x and object._y! ;-)

Daniel Jäger
  • 177
  • 1
  • 3
  • 13