MovieClipLoader class

For some reason, I'm having difficulty wrapping my head
around how to implement and use the MovieClipLoader class. Here's
where I'm stuck. I have a bit of code that looks like this:
function showImage(filename:String):Void {
var image:MovieClip = imagePlaceholder_mc.image_mc;
image.loadMovie(filename);
//Center images
xPos = (900 - image._width)/2;
yPos = (600 - image._height)/2;
image._x = xPos;
image._y = yPos;
imagePlaceholder_mc._alpha = 0;
imagePlaceholder_mc.onEnterFrame = fadeIn;
Now, whenever showImage() is called, the picture loads and
properly fades in. However, the image is not correctly centered.
However, if showImage is called a second time on the same image,
THEN the image properly centers. Basically, showImage uses the last
._width and ._height values. I assume this is because the clip
hasn't finished loading when xPos and yPos are set, and that if I
had the calculations occur when the .jpg is completely loaded, then
the correct results will occur.
However, I can't seem to figure out where to put my
MovieClipLoader class, where to stick the listeners, or anything.
I'm having some sort of problem conceptualizing how the class is
supposed to work, and for some reason the tutorials are not helping
me out. If it were explained to me in relation to the code I have
above, it would help.
Thanks,
Peter

Can't really explain it in terms of your code above because
it is different that your code above. The MCL just gives some nice
packaging to starting, progressing through, and ending, the load of
external assets. The listeners just listen for the different
"events" in this process and then can run certain bits of code when
those events happen.
So lets go to it. We start out well enough:
function showImage(filename:String):Void {
Then we need to make an instance of our MCL. It is also
possible to have it outside your function, but for now lets keep it
inside.
var myMCL:MovieClipLoader=new MovieClipLoader;
Next we need to make an object to attach the various events
to. There are a lot of ways they could have designed this, but this
is how they did it so that is what we do!
var myListener:Object=new Object()
Now there are several different events that the MCL might
have, but for the moment we are going to worry about only one of
them. You want to do something when the external asset is fully
loaded – you can't set the width or height until after the
whole thing is done.
myListener.onLoadInit=function(target:MovieClip){
Pos = (900 - target._width)/2;
yPos = (600 - target._height)/2;
target._x = xPos;
target._y = yPos;
target._parent._alpha = 0;
target._parent.onEnterFrame = fadeIn;
Notice how basically your same code goes in there, but with
the difference of target? (BTW, I could have called that grapefruit
or anything I wanted, but target seemed good.) That is because the
onLoadInit event returns a reference to the thing that has just had
content loaded into it. So we can use that instead of having to
hard code the names of our movie clips. That makes it a lot more
flexible.
Okay we could now issue our load, close up the braces, and be
done with it. But we still have one more thing. Let's look at what
we have. We've made a function that sets up an MCL, makes and
Object to hold listeners, and set up an event inside that object.
But we still haven't told our MCL instance that it needs to report
its events to that object.
It is a great philosophical debate of whether events happen
if there is nothing there to listen for them! :) But on the
practical side, nothing will happen if we don't tell flash to
listen for them. That is way we need the next line:
myMCL.addListener(myListener);
That tells our MCL that when it has events it needs to tell
myListener about them. Now the MCL has many events onLoadStart,
onLoadProgress, etc. and it will dutifully tell our listener object
about them. Inside that listener we have only set up an action for
one of them, but hey, laissez les bon temps rouler.
So finally we can issue our load statement and close up the
braces.
myMCL.loadClip(filename);
So what happens?
You call your function and pass it the filename.
An MCL is created.
A listener object is created.
Object is given an event handler function.
The MCL is told to report its events to that Object.
The MCL starts loading the file.
The MCL has a onStartLoad event and reports it to the object.
Nope no handler for that, nothing to do.
Several times in a row the MCL has an onLoadProgress event,
and reports it.
Nope no handler for that, nothing to do.
etc.
Finally there is an onLoadInit event – the file is
ready to be mucked with. The MCL reports it to the object, and hey
there is something to do.
So the MCL tells the objects onLoadInit function, "I just
Inited, the following clip."
The function then takes that information and applies the
things you specified.
And that is pretty much it.
A couple of notes. The onLoadProgess event doesn't happen
when you are testing locally. So you won't see it.
It is a good practice to get into that when you are done with
something you remove the listener. So you might want to add the
following line to your onLoadInit function.
myMCL.removeListener(myListener);
(At least I think that is a good idea. I haven't done that
myself in the past, but I have recently become much more aware of
how important it is – at least generally – to remove
listeners. So if you get an error just remove that.)

Similar Messages

  • Preloader and moviecliploader class

    Hello
    Firstly thanks to kglad for some advice yesterday. More needed
    I am using FlashMX 2004 Professional.
    I have been having problems with my preloader which i have placed as a movieclip at the start of the pertinent scenes where it is needed. The problem has been one of file size in frame one -  a common problem I beieve. This causes the preloader script to malfunction and come in late and show just 100% loaded of the preloader animation - again a common problem I am reading. SO it seems clear having designed the whole website using LoadMovie Number that the movieClipLoaderClass would be the solution to getting my Preloader to work. Hmm..
    So can people tell me that if I now create a seperate scene for the preloader and have it listen for any downloading swf to activate using the moviecliploader class will this work ok in tandem with how I have connected all the other scenes using the loadmovienumber? Just need to now before I start trying that out. My hope is that the Preloader will then overcome the file size issue of the first frame because and it will not have to load itself every time afresh.
    Hope this makes sense, I am fairly inexperienced here...
    Cheers
    Pete

    I know everything about the file, I know that the sound starts on the first frame and also I know it ends on the last frame. If the sound data are on the main timeline, the sound could be streamed and you don't have to load it fully to start playback. The question is the same, how much I need to load to start the sound.
    I think it's not very clear why I need this. Imagine:
    - you need to play the external SWF file
    - you start to load it via the MovieClipLoader class
    - onLoadInit you stop the movie and wait for the load
    - check, if you can run the movie - based on bytes and/or frames you can determine, you preloaded enough, so the movie won't be stopped and you don't have to load more to continue
    - but, when you run the movie, the animation starts, just the sound doesn't, because more of it needs to be loaded.
    - then after short time the sound start to play and since it's streamed and on the timeline, it's sync with the animation
    So, in this scenario a few seconds of the sound are skipped / missing in playback. Of course, it could happen that the sound runs fine, because the SWF content could be different. I can't say 20% of the file size is audio and the rest is the animation.
    I wanted fully flash solution, but it seems I'll have to find it in combination with Java, because it seems there is no way to distinguish between audio and other data in the Flash movie in AS.
    Anyway, thank you for your help.

  • MovieClipLoader Class doesn't allow function calls

    I have functions within a movieClip that loads into a main
    movie. The functions operate with no problem when using loadMovie
    method, but I need to execute some script after loading so I
    switched to the movieClipLoader class instead.
    Problem is, after the movieClip is loaded, any function calls
    from a keyframe (or even a button) are totally ignored.
    What am I missing. Should I be doing something different?
    here is my movieClipLoader code:

    Actually, I think I found the solution after looking at some
    other posts. I changed "onLoadComplete" to "onLoadInit" and it
    worked.
    As I found in another post, onLoadComplete doesn't mean all
    of the code is loaded yet, but onLoadInit means the movie and code
    is loaded.

  • SetMask in a custom class

    Gosh I am having a nightmare I am trying to set a mask on an
    img I have loaded into a movieclip in a custom class. But no matter
    what it ain't working, any ideas. Here is essentially what I am
    trying to do:

    I second that notition. Use the MovieClipLoader class and use
    the onLoadInit handler to apply the mask once the image is
    loaded.

  • Problem Loading swf with MCL class

    Hey, I am relatively new to actionscripting and am having a
    bear of a time trying to figure out why this won't
    load.....basically i am trying to use the movieClipLoader class to
    call up a swf..... so basic i know..This is my script
    any help here?

    does container exit on the timeline that contains your code?
    is master.swf in the same directory with your flash swf and
    html?

  • Help with MovieClipLoader

    I know there's a million posts about this topic (believe me,
    I've been through most of them) but there is nothing that seems to
    fit my problem. No matter what I do, I cannot get my external swfs
    to load into the main swf of my project. I know the key pretty much
    lies in the MoveClipLoader class, but I'm also fairly certain that
    I'm missing something very important which would and should not
    come as a suprise. This is the code I am using in my main swf:

    All of my SWFs are in the same folder, but using the absolute
    URL made everything fire correctly. Thanks for the help. I do have
    another question, though. I've been working under the impression
    for some time that you only need to have your files in the same
    folder and then just make reference to them. Is this not the case
    or is it something specific to the MovieClipLoader class?

  • TabIndex doesn't work with MovieClipLoader

    Hi, not sure if this is a common issue with flash or
    something to do with my file, but no tab indexing is working when I
    load swfs using the MovieClipLoader class.
    The tab indexes I am declaring are only for btns in the main
    swf, if I delete the MovieClipLoader actions, the tabIndexing works
    fine.
    Any ideas?
    Any help greatly appreciated
    Cheers
    Dave

    Hi Sanjit,
    I've tried this on multiple PCs and get the same problem everywhere.
    See picture with IE11 and chrome.
    Sincerely,
    Davy

  • MovieClipLoader - end of play flag

    Hello all,
    I am making a
    movie slideshow viewer with sound. I would like the
    functionality to be similar to a self-playing
    still image slide viewer, but with each "movie slide" being
    a small SWF movie with sound. Each of these individual "movie
    slides" varies in length (time).
    My plan was/is to create a "master.swf" which uses the
    MovieClipLoader class to load in each of the individual "movie
    slide" SWFs (which would be named "slave_0.swf", "slave_1.swf",
    "slave_2.swf" etc...). The problem with this method is that I do
    not know how to have my loaded SWF movie slide (slaves) "tell" the
    "master.swf" file that, ok, I have loaded
    and played my entire timeline, so it's ok to load up the
    next slave. Is there a nice way to have the slave (loaded via MCL)
    tell its master that it has finished playing its timeline and that
    the master now needs to bring in the next slave?
    Or, is it better to stream all of my SWF's into FLV files and
    use a NetStream class?
    Any info would be very much appreciated.
    -john

    > but you can, in the last frame of each slave, place a
    function call back
    > to the master that lets the master know the last frame
    has played.
    How would this function in the slave's last frame look?
    Something that just sends a variable back up to the master, or
    what?
    > ...or you can initiate a loop in the master that
    continually checks the play-progress of the slave.
    How would this loop look? Some sort of OnEnterFrame deal?
    Thanks for input thus far -- appreciated!
    -john

  • MovieClip Loader Class - assigning Events to Movies

    Hi.
    I have a MovieClipLoader Class that loads a SWF into a holder
    clip that is on my main timeline. Then Im using
    "mclListener.onLoadInit" to check that the SWF is loaded so that I
    can continue to load some buttons into the holderclip from an XML
    file.
    Issue:
    First my MovieLoader checks that the SWF is fully loaded.
    After that, how can I check that those XML Buttons that go inside
    that SWF are fully loaded. I want to assign events to them. My code
    below works, until the point where I start assigning OnReleases to
    the loaded XML buttons. I thought XML.OnLoad did that, but it
    doesnt seem to work.
    Id be grateful for anyone's help
    Thanks
    Ryan

    It is called the Loader class and it is very similar –
    and yet completely different!
    Of course you can always publish to AS2 and still use the MCL
    if you wish.

  • Tween Class Help

    Hi everyone. I'm doing a website and I'm having trouble with
    something. I have a movieclip that I want to animate using the
    tween class. however, I want thetween to occur once the frame that
    the code is on loads. This is a problem because I can't use
    onEnterFrame because it will play thetween continuously. I need it
    to play oncethe frame loads and only once. I tried using the
    movieclip.onLoad function but it's not working for me. What am I
    doing wrong? Here is the code that I'm using...

    If the code is in an externally loaded Movie you need to
    determine when the frame is available and the general way to go is
    using the MovieClipLoader class.
    If the code is in a already loaded movie then follow
    naomind's recommendation

  • Sound class

    Hi everyone. I'm creating an audio player which will receive
    xml information from a server and play the requested sone. I have
    all that set up. The only problem I'm having with is creating the
    progress bar while the sound is streaming. What happens is when the
    audio player is opened, the song starts playing because of the
    streaming property that I set in the actionscript, but the progress
    bar doesn't show up until the song is fully cached on the user's
    machine. So the effect is you don't see the progress bar when the
    audio player opens and the song plays. Instead the progress bar
    will appear a couple of seconds after the audio player starts
    playing. I've put the project up on my site, so you can take a look
    at it and see what I'm talking about,
    www.mark-yieh.com/airspun/newaudioplayer.html. If you know how to
    fix it please let me know. It will really be appreciated. Thanks.
    I've looked at all the event handlers in the sound class, but none
    of them let's me gather information from the sound file until it's
    fully loaded. For example, with the MovieClipLoader class, there's
    an onLoadInit handler and an onLoadStart handler and an
    onLoadProgress handler, but there's none for the sound class. Is
    there another solution?

    if you're attempting to get the sound.duration before it has
    loaded, then you'll find that this will only return the number of
    seconds downloaded so far. sound.position should work okay though.
    check out the comments in
    livedocs
    for sound duration for some handy ways to approximate this
    property during streaming.

  • MovieClipLoader - broken link in documentation

    There is broken url in example for MovieClipLoader class documentation. I saw a link http://www.fakedomain.com/images/bad_hair_day.jpg for few times for example http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001384.html

    Based on the domain name I would say it wasn't meant to be a genuine link, only an example, though they could have used more fake to make it clearer... http://www.fakedomain.com/fakefolder/fake-image.jpg

  • MovieClipLoader not working asynchronously

    I'm using the MovieClipLoader class to load a swf. When the
    loadClip method is invoked everything stops until the load is
    complete. This makes it impossible to load in the background, or to
    show load progress using onLoadProgress. The swf being loaded is
    about 8mb. Is the file size causing this issue?

    Yes, the swf contains an embedded video file and needs to be
    loaded from a cd. Using a flv for this particular movie is no
    longer an option. I had originally planned on using flv, but
    testing revealed major playback issues when playing an flv of this
    size/quality from a disc. There will also be some interactive
    objects involved with the animation. Instead of embedding the
    video, I'm going to try exporting the video frames to jpgs and
    importing the sequence. If not, I may be stuck with a static
    loading screen. Thanks for the reply.

  • MovieClipLoader bug

    I’ve noticed that if you close an Internet Explorer
    pop-up window while flash is downloading more then 2 items using a
    MovieClipLoader class the parent window will refuse to load any
    more content from the domain of the flash movie. I can post a
    sample if requested.... Is this a known bug?

    The components you're having trouble with create their popup
    ui in _root.
    For example, the list part of the ComboBox is created in
    _root. But if _root
    doesn't have the necessary assets in its library, that part
    of the component
    cannot be created. In your case, you can either add all the
    components to
    library in your topmost movie or use _lockroot to force the
    popup parts to
    be created in the loaded movie.
    Example:
    this.createEmptyMovieClip("components_mc",
    this.getNextHighestDepth());
    var lo:Object = new Object();
    lo.onLoadInit = function(target_mc){
    target_mc._lockroot = true;
    var mcl:MovieClipLoader = new MovieClipLoader();
    mcl.addListener(lo);
    mcl.loadClip("components_mc.swf", components_mc);

  • Magnify effect in photo gallery, need help...

    Heya,
    So if you visit
    http://www.hookmedia.biz/cabinet_source/v4_f
    and navigate to the "Gallery" page you'll see that, below the area
    the large photo is displayed, there is a "film strip" of thumbnail
    photo's. I need these photos to be magnified when you mouseover
    them but I'm unsure of exactly how to do that. Can anyone help?
    You can download the entire .fla via this link:
    http://www.hookmedia.biz/cabinet_source/v4_f/index/fla
    Once downloaded, double click on the main content area
    (titled content_mc) and navigate to the second frame and open the
    "photo_gallery" or "gallery" folder where you'll find the first
    layer is actionscript for the photo gallery.
    Thanks!

    You rollover code doesn't work because you are assigning the
    functions
    before you load the images. The loaded images remove your
    code. You should
    not use loadMovie and use the MovieClipLoader class instead.
    Then, in its
    onLoadInit method you can assign your functions - so that
    they are assigned
    after the clip is loaded. Also, I'd either just create empty
    clips, on the
    fly, to load into or attach from the library. And
    duplicateMovieClip is not
    a property it is a method - calling like you are doing will
    not work. If
    you'd look in the Help you'll see that duplicateMovieClip can
    accept an init
    object, and also returns a ref to the new clip... So your
    code can be much
    simplified:
    this.holder.duplicateMovieClip; //duplicates the MC holder
    already on the
    stage
    this._name = "e"+i;
    this["e"+i]_x = _x + 50;
    this["e"+i]._alpha = 50;
    To:
    this.holder.duplicateMovieClip("e" + i,
    this.getNextHighestDepth(),
    {_x:theX, _alpha:50});
    And you can't set _x to _x + 50 like that... for one you'd
    need to use more
    like this._x = this._x + 50 or this._x += 50. But it still
    won't work here
    since all the new clips are going to be created at x=0. You
    need to
    increment a variable... or base the spacing on your loop
    variable, i - like
    i *50.
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

Maybe you are looking for