I’m loading a image into a sprite:

var loader:Loader = new Loader();

addChild(loader);

loader.load(new URLRequest(“ball.png”));

But if I try to resize the sprite the image stays the same
size and the width of the sprite reports as zero. If I add graphics
as in:

graphics.beginFill(color);

graphics.drawCircle(0,0,radius);

graphics.endFill();

var loader:Loader = new Loader();

addChild(loader);

loader.load(new URLRequest(“ball.png”));:

I can then resize the sprite and the image changes size
accordingly and the sprite width is as expected. Why? How do I have
the image resize as the Sprite resizes without adding graphics
(which are not required).|||
your image doesn’t resize in the movieClip because you apply
width and height while the image isn’t totaly loaded into the
movieClip.

Once the image is completely loaded, the movieClip get the
width/height image properties, forgetting the ones you tell it to
use.

If you want to resize your image, you have to :

- wait untill it s completely loaded before applying
with/height properties.

or

- use the _xscale and _yscale properties whenever (they can
be applied and remembered even if the image isn’t totaly
loaded)|||
Since the graphic isn’t there yet, the only width and height
the clip has to relate to is 0 0 meaning that the xscale/yscale
which are set when you set a _width _height to an object (relating
to it’s total _wdith _height) stay 100.

You have to add an event to trigger the scale function once
the image is loaded. Since I’m not very familiar to AS3 loading I’m
not sure, but back in AS2 a movieclip could have a bytesLoaded
equal to the bytesTotal but still could have no image drawn (I
think even using an onEnterFrame function the image sometimes could
wait a frame or two to be drawn once loaded). So the proper check
to really see if an image had been loaded into a movieclip was to
check the _width to be above 0. I suggest you do the same. It will
be alot less performance demanding than drawing a circle, also, if
your circle’s radius does not match the image size the scale of the
image once loaded could be off.

Related posts:

  1. Duplicate image loaded into Loader Object
  2. get width and height of a dynamically loaded image once it’s done loading?!
  3. Create bitmap of dynamically loaded image
  4. buttonMode on a loaded movie
  5. Script access for loaded SWFs in Flash CS3

Related posts brought to you by Yet Another Related Posts Plugin.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 free icons download Suffusion theme by Sayontan Sinha

Featuring Recent Posts WordPress Widget development by YD