A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: createemptymovieclip height width

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326

    createemptymovieclip height width

    I'm trying to trace the height/width of a loaded jpg file:
    Code:
    this.createEmptyMovieClip("logo_mc", 999);
    loadMovie("test2.jpg", logo_mc);
    trace (logo_mc.width);
    trace (logo_mc.height);
    This doesn't work. I gives undefined. I've read that first I would have to let Flash know that the jpg has been fully loaded. How would I do that? I've tried using getBytesLoaded/getBytesTotal, but then it gives 0 for both getBytes.

    Also used stuff like this, but that doesn't work either:
    Code:
    this.createEmptyMovieClip("logo_mc", 999); 
    loadMovie("test2.jpg", logo_mc); 
    logo_mc.onLoad = function() {     
    trace (logo_mc.width);    
    trace (logo_mc.height); }
    How do I check whether the jpg has been fully loaded before I can show/alter it's dimensions?

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    have a look in the Help files for the MovieClipLoader class

    MovieClipLoader.onLoadInit event listener
    When this listener has been invoked, you can set properties,
    use methods, and otherwise interact with the loaded movie.

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326
    Yes, already found that one. Still, I was wondering if something like that could also be done using createEmtpyMovieclip and LoadMovie. Thought of something myself (see below). Is that the way this previously was done? Or is there a more efficient way of doing this using LoadMovie?

    Code:
    this.createEmptyMovieClip("logo_mc", 999);
    loadMovie("test2.jpg", logo_mc);
    this.onEnterFrame = function() {
        if (logo_mc.getBytesTotal() != false) {
            if (logo_mc.getBytesLoaded() == logo_mc.getBytesTotal()) {
                trace(logo_mc._width);
                trace(logo_mc._height);
                delete this.onEnterFrame;
            }
        }
    };

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    an empty movieclip has zero width and height
    you can check for these properties in an OEF loop

    PHP Code:
    this.createEmptyMovieClip("logo_mc"999);
    loadMovie("test2.jpg"logo_mc);

    this.onEnterFrame = function() {
    trace(logo_mc._width);
    if (
    logo_mc._width 0) {
    trace(logo_mc._width);
    delete this.onEnterFrame;
    }
    }; 

  5. #5
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326
    And this width/height is only set if the image to be loaded has been fully loaded inside the first empty movieclip? So while it's loading it is still regarded as an empty clip with dimensions 0?

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    the external file must load into and instanciate the movieclip
    before its properties are able to be accessed.

    best practice is to use the MovieClipLoader.onLoadInit event,
    which is called after the content is loaded and fully initialized.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center