Welcome, Guest
  • Author Topic: getting size of dynamically loaded image  (Read 1940 times)

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    getting size of dynamically loaded image
    « on: 08/03/04, 06:06 »
    I am trying to resize an empty movie clip that loads dynamically a jpg, once i strech my flash movie with HTML to Exactfit.
    I  pass a variable from HTML that infrom flash of the size of the stretched flash movie.
    the rest you will understand by reading the script.
    The only problem is that I get undefined for the value of the empty MC.
    I guess it has to do with the fact that it's a dynamically loaded image that sets the width of it.

    var size_arr = size;//loaded parameters from HTML
    empty_MC.width = empty_MC.width*(Stage.width/size_arr);
    traceTxt.text = empty_MC.width // this gived "undefined"
    any ideas?
    Greetz,
    Al

    Update :
    I keep on updating my post here the more I learn.

    I am trying to get the size of a loaded jpg movie clip.
    I use:
    size = _root.empty_MC", _width;
    but then it returns "0".
    I suppose it is because the image is not yet loaded. So i used another code:
    if (_root.fade.ImageNew.loadMovie = true){
    size = _root.empty_MC._width;
    }

    Still returns "0".

    pls help
    « Last Edit: 08/03/04, 11:43 by Algreco »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:getting size of dynamically loaded image
    « Reply #1 on: 08/03/04, 16:03 »
    hi, you analysed right ;) You have to wait until the movie is loaded.
    There is a event fired (loaded), when this happens.
    Inside a eventhandler for this event, you can ask for attributes, or change them as you like.
    happy flashing
    8)
    Ronald

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    Re:getting size of dynamically loaded image
    « Reply #2 on: 08/03/04, 16:30 »
    Ronald, thanks for answering.
    The image loaded is called during a case of a switch tag. Here is my actual code:
    Code: [Select]

    case 0://C R O S S F A D E R
    //load images
    _root.fade.ImageNew.loadMovie ("homer.jpg");
    _root.fade.ImageOld.loadMovie ("alex.jpg");
    _root.fade._visible=true;  //hide/show effects
    _root.fade.gotoAndPlay(2);
    // image sizing

    size = _root.fade.ImageNew._width;
    Imagewidth = size*(Stage.width/size_arr);
    //_root.traceTxt.text = "size is  " + size;
    _root.traceTxt.text = Imagewidth ;

    --------------------------------------
    here I tried to improvise on what you were suggesting
    but I think I got it wrong :(

    _root.fade.ImageNew.onClipEvent (load){
    size = _root.fade.ImageNew._width;
    }
    _root.traceTxt.text = size;

    Could u please let me know what I should do?

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:getting size of dynamically loaded image
    « Reply #3 on: 08/03/04, 16:42 »
    If the loaded clip is a swf, you can make itself active ;)

    Which means, you can make the loaded movie inteligent enough to inspect its environment.

    Write the adaption function into the first frame of the new clip.
    This way you are sure, it is completely loaded and can be influenced, and it controls itself ;)

    Or, you can make the movieclip call a function in the root, which is then controlling it.

    happy flashing
    8)
    Ronald

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    Re:getting size of dynamically loaded image
    « Reply #4 on: 08/03/04, 16:45 »
    I have to avoid loading a swf. It's a sort of a slide show, so i am loading jpgs into empty MCs. It's that empty MC I want to detect the size of so I can resize the image so it doesn't tretch with the flash movie.  :-\

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:getting size of dynamically loaded image
    « Reply #5 on: 08/03/04, 16:58 »
    The you just can use the onLoad event, to modify youre clip:

    myMC.onLoad=function(){
       if(this._width>200){
         //reduce by a factor ...
         factor=200/this._width;
        this.xscale=100*factor;
        }
    }

    maybe you have to do something like it with the height too ;) then you have to use the max factor you receive.
    happy flashing
    8)
    Ronald

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    Re:getting size of dynamically loaded image
    « Reply #6 on: 08/03/04, 17:38 »
    Good idea, but I don't manage to make it work :(.
     I put the following exerpt of your script under case 0:
    case 0://C R O S S F A D E R
    //load images
    _root.fade.ImageNew.loadMovie ("homer.jpg");
    _root.fade.ImageOld.loadMovie ("alex.jpg");
    //_root.traceTxt.text = "Image loaded";// checks out fine
    _root.fade.ImageNew.onLoad=function(){
    _root.traceTxt.text = _root.fade.ImageNew._width;
    }

    wanted to see if it functions, but I get nothing, as if it doesn't load the image.
     if only I could get this to work I have all the ingredients I need to resize the MC  :'(
    « Last Edit: 08/03/04, 17:39 by Algreco »

    Algreco

    • Seasoned Programmer
    • ***
    • Posts: 123
    • If it 'aint workin blame Flash!
      • View Profile
      • Line Dezine
      • Email
    Re:getting size of dynamically loaded image
    « Reply #7 on: 08/04/04, 05:27 »
    OK, I'm almost there!
    I found on the net some information about loading attributes of loaded images with the "data" tag.
    So here something that works - If I attach this script to the empty movie clip I load the image into I get a correct trace:

    onClipEvent(data) {
    trace (this._width)
    }

    But I wish to access this from the main timeline and not attach it to the movie clip. So I tried this code:
    obj = _root.fade.ImageNew.data
    obj.onLoad=function(){
    trace (_root.fade.ImageNew._width);
    }
    I am sure I am writing it wrong. Could you please correct me?
    8)