ActionScript 3.0 Getting Size/Coordinates From Loader Content

Posted by TheDarkIn1978 on Stack Overflow See other posts from Stack Overflow or by TheDarkIn1978
Published on 2010-03-23T08:22:21Z Indexed on 2010/03/23 8:23 UTC
Read the original article Hit count: 312

Filed under:
|
|
|
|

i'm attempting to position a textfield to the bottom left of an image that is added to the display list from the Loader() class. i don't know how to access the width/height information of the image.

var dragSprite:Sprite = new Sprite();
this.addChild(dragSprite);

var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest("picture.jpg"));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayPic, false, 0, true);

function displayPic(evt:Event):void
    {
    dragSprite.addChild(evt.target.content);
    evt.target.removeEventListener(Event.COMPLETE, displayPic);
    }

var tf:TextField = new TextField();
tf.text = "Picture Title";
tf.width = 200;
tf.height = 14;
tf.x //same x coordinate of dragSprite
tf.y //same y coordinate of dragSprite, plus picture height, plus gap between picture and text

addChild(tf);

within the displayPic function, i could assign the evt.target.content.height and evt.target.content.width to variables that i could use to position the text field, but i assume there is a better way?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about get