FORUMS: list search recent posts

Access to Movieclip Parameters

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Access to Movieclip Parameters
on Sep 19, 2006 at 8:47:00 pm

Hi. I'm still fairly new to actionscript so pardon if this is a dumb question. I've searched all the flash help I could find including this forum and haven't found an answer...

I want to dynamically load images into an empty movieclip. That part is easy. What I don't seem to be able to figure out is how to access the _height and _width parameters of the movieclip/image. The following code is a sample of what I mean:

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var image_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace(target_mc._name+" = "+target_mc._width+" X "+target_mc._height+" pixels");

/* I can access the height/width parameters correctly here, but I need access to this info outside of the onLoadInit function */

// return target_mc;
image_mcl.loadClip("lilly1.jpg", image_mc);
// At this point I would think I could use the following to the get the correct height:
// But I get '0' instead of the actual height (same with width).

Am I barking up the wrong tree? Any ideas would be appreciated.

Return to posts index

Re: Access to Movieclip Parameters
on Sep 19, 2006 at 11:27:51 pm

You're thinking to linearly about the code. Flash will execute ALL the code in a frame within the timeframe of the frame (say for example 1/12th of a second if your SWF is set to 12 frames per second) UNLESS the code is specifically designed to execute based on some other event. The onLoadInit is such a code block. Until Flash has COMPLETELY downloaded the image, it does not know what the image's width and height are (this is why you're getting 0 for the width and height). The onLoadInit function is designed to execute once the file has been fully downloaded (technically it runs after the first frame has been executed in the case of it being a SWF, but you're dealing with a JPG or PNG here I assume, so frames are not really relevent, and onLoadComplete would work the same in this case...) So you can't access the _width or _height of the loaded image UNTIL the onLoadInit has fired, so anything you want to do with those properties should be done in the onLoadInit (or onLoadComplete) function or afterwards.


I'm filling a need. Without me there would be no bad examples.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved