A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: onData, onLoad and actions performed with createEmptyMovieClip

  1. #1
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745

    onData, onLoad and createEmptyMovieClip actions

    Hey all. Check this out:
    I want to load pictures to make a gallery. I thought I could do something like:
    Code:
    _root.createEmptyMovieClip("x", 1);
    _root.x.onData = function() {
    	this._width /= 2;
    	this._height /= 2;
    }
    _root.x.loadMovie('IMGP0001.JPG');
    But that can't be done. I mean, if I make:
    Code:
    _root.createEmptyMovieClip("x", 1);
    _root.x.onData = function() {
    	trace(this._height);
    	trace(this.getBytesTotal());
    }
    _root.x.loadMovie('IMGP0001.JPG');
    I get an output like:
    Code:
    0
    617
    when the height of the pic is 960px and 150930 bytes.

    Another thing, if I make:
    Code:
    _root.x.onData = function() {
    	this.stat += "ondata\n";
    }
    _root.x.onLoad = function() {
    	this.stat += "onload\n";
    }
    _root.x.loadMovie('IMGP0001.JPG');
    and get to trace _root.x.stat, I get 'undefined'.

    Also, on things like that, what performs first? onData or OnLoad?

    Thanks in advance,
    Leonardo Lima

  2. #2
    Member
    Join Date
    Jun 2002
    Posts
    61
    Got the same problem. Haven't found the answer yet.
    But I'm also very currious for the answer!

  3. #3
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    one way is like this;
    this goes on the first frame of the main timeline.
    Code:
    this.createEmptyMovieClip("x",1);
    x.loadMovie("IMGP0001.JPG");
    this.onEnterFrame = function(){
    trace(x._height);
    trace(x.getBytesLoaded()/1024);
    }
    The output will read; the height and kbs of the loaded image.

    Hope this helps

  4. #4
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    It works as told, but I only wanna set this once. I can have a 'if(!allset) { ... allset = 1 ...}' condition but imagine 40 onEnterFrames. Won't that be too much?

    Thanks,
    Leo

  5. #5
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    What exactly do you want to do?
    The term "this.onEnterFrame" applies to the timeline in the frame that it's in.
    Everything underneath the term will execute when the playhead of the timeline enters that frame.

  6. #6
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    What I wanna do:
    - resize the pictures
    - set X/Y coords according to some math

    For that I don't need a onEnterFrame, just once is enough...

    Thanks,
    Leo

  7. #7
    (sic) Covenent's Avatar
    Join Date
    Dec 2000
    Location
    Ireland
    Posts
    709
    You should just be able to do the following:

    Code:
    this.createEmptyMovieClip("mc", 0);
    this.mc.loadMovie("myImage.jpg");
    this.mc.onData = function () {
    trace(this._width); // find images width
    trace(this._height); // find images height
    }
    The obviously you can do anything from there such as resizing the mc, repositioning it etc.

  8. #8
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    I CTRL+C/V and it didn't worked... It never traced anything...

    Can you make a sample?

    Thanks,
    Leo

  9. #9
    Member
    Join Date
    Jun 2002
    Posts
    61
    Didn't work for me either!

    Shouldn't you be tracing

    Code:
    this.mc._widht
    this.mc._height
    instead of

    Code:
    this._widht
    this._height


  10. #10
    Member
    Join Date
    Jun 2002
    Posts
    61
    This is my situation.

    The picture is loaded without any problems, but the onData
    does not work I never see the text "I'm in"!

    Code:
    function loadPicture(picName){ 
    
    Window.Foto.jpgHolderInst.loadMovie(slidePath+picName);     
    
    Window.Foto.jpgHolderInst.onData = function() {
       trace("I'm in!");
       }
    }

  11. #11
    Member
    Join Date
    Jun 2002
    Posts
    61
    Ok, maybe some answers.
    I searched a bit in the forums and this is what I came up with

    It seems like onData and onLoad don't work with loadMovie, but only with loadVariables.

    Check these out

    Same problem
    http://board.flashkit.com/board/show...hreadid=325958

    http://board.flashkit.com/board/show...hreadid=326336

    And some workaround from flashguru
    http://board.flashkit.com/board/show...hreadid=340302

    I also found a link to the site of flashguru with a article
    about this subject but the site was down, but here is the link anyway
    http://www.flashguru.co.uk/000053.php


  12. #12
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    Sure, but it isn't saying so at the AS Dictionary:
    'Event handler; invoked when a movie clip receives data from a loadVariables or loadMovie call.
    You must define a function that executes when the event is invoked.'
    (from $flashpath\Help\Flash\html\30_asd_07_m80.html).

    Did you try that workaround?

    Regards,
    Leo.

  13. #13
    Member
    Join Date
    Jun 2002
    Posts
    61
    Tried the workaround, but with no success!


  14. #14
    Member
    Join Date
    Jun 2002
    Posts
    61

    About the workaround

    I tested the workaround.
    The test code provided by flashguru works allright.
    But my own loadMovie does not!


  15. #15
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    What do you mean by 'your own'?
    And do you have ICQ or so so we can talk?

    Regards,
    Leo

  16. #16
    Member
    Join Date
    Jun 2002
    Posts
    61
    With my own, i ment my own code.
    When I just copy and paste it didn't work.

    But I just got it all working.
    The workaround works!

    My appologies to flashguru for ever questioning his code!


  17. #17
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    So we must use the workaround. Ok then.

    Regards,
    Leo.

  18. #18
    chatbugs.com ***** flashTampaDotCom's Avatar
    Join Date
    Mar 2002
    Location
    Tampa, Florida
    Posts
    171
    Perhaps this thoroughly commented example will help you guys.. I made it a couple of months ago.. it's Flash5 and MX compatible.

    http://www.flashtampa.com/flashtutor...onalReSize.fla
    http://www.flashtampa.com/flashtutor...onalReSize.swf

  19. #19
    Member
    Join Date
    Jun 2002
    Posts
    61
    Jayson,

    Tnx.

    You've placed comment that it cannot be run in the flash environment, but I just changed your jpg for one of mine and
    ran the bastard on my local machine with no probs!
    It worked like a charm!
    It's exactly what I needed.

    I will use this in my project.

    tnx again,

    biker66

    [Edited by biker66 on 07-22-2002 at 07:51 AM]

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