dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Preloading - technique and application

  1. #1
    Junior Member
    Join Date
    Jul 2001
    Posts
    8
    I have a flash movie which needs to display potentially about 12 pictures (JPEG format each around 25k). Now not all the pictures need to be available on starting the movie, however I would like to load them in the background should they be requested. On starting the movie only one picture needs to be loaded. The pictures are saved as SWF files.

    Question
    How is it possible to load up pictures (SWF's) in the background ready for use if need be. And when the user requests to view a picture the appropriate SWF gets loaded into a movie clip which is called 'mcHolder'.
    Should they be loaded up at an arbitrary level (eg level 100) and then somehow placed into mcHolder when requested?
    Alternatively once they have been loaded they will have been cached, so when the user requests a picture it could be loaded *again* this time into mcHolder (it would be much quicker the second time).

    In a nutsshell my question is:
    What is the method used for loading SWF's in the background which may then be used by the movie as and when necessary?

    Thank you in advance
    regards
    Sanjiv

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    I would put however many swf's you want to use as keyframes in your mcHolder and use:

    frmae1:
    loadMovie ("picture1.swf", "mcHolder");
    frame2:
    loadMovie ("picture2.swf", "mcHolder");
    frame3:
    loadMovie ("picture3.swf", "mcHolder");

    etc
    etc

    this will load an SWF into the mcHolder clip if you tell the timeline to goto each frame. If you want, you can put some preloader at the beginning of each picture.swf and/or call a preloader function in mcHolder from picture.swf, passing bytesloaded(), bytesTotal() etc

    I think this will work best if you want preloaders, and/or you could load all of them in the background and use a combination _level0._visible=false; or mcHolder._visible=false; or unloadMovie(levelNo) to show or hide them

    Sam

  3. #3
    Junior Member
    Join Date
    Jul 2001
    Posts
    8
    Hello Sam,

    Thank you for your reply,

    I would like to ask the following:

    If I loaded the 11 remaining swf's in the background, does that mean loading them at an arbitrary level (and making the level invisible)?

    Secondly, If the user requests a swf, what is the procedure to shift that swf from this arbitrary level into a movie clip, or is the only way to do this is to load it again, this time into the movie clip? (meaning that the only benefit of loading an swf into the arbitrary level is so that it gets cached). Am I on the right track...or Am I barking up the wrong tree?

    kind regards
    Sanjiv

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    I's a bit tricky cos loading into _levels allows you to make a _level visible or not by setting _visible and allows you to unload a movie from its _level and you won't need to use keyframes just replace it into the same level...

    ...however, loading into a mcHolder (target) doesn't allow levels, just target movieClips with depths, so thats why each one has to be in its own subMcHolder (target) on each frame cos you can't unload it or make it visible or not directly, only by moving to another frame or setting its host MC to _visible or using swapDepths()!

    Also. you can't move loaded swfs from one movieclip or level to another or put them all in one level and move them somewhere else after they have loaded, unless you unload it and then load it again in the place/ level you want it to be placed!

    Sorry, it's really hard to explain as there are lots of different ways to do it, but i think this how i would do it:

    mainMcHolder:
    contains 12 keyframes each with a loadmovie action and stop() action. Each of these keyframes holds an empty (target subMcHolder) movieclip to act as the target for each swf you load using action loadMovie. Maybe leave frame 1 empty with 12 actions to load all 12 picture.swf's into their targets at the same time! This way they load in the background silently

    buttons:
    A button(s) wherever you have them, tells mainMcHolder to goto and stop at one of the 12 keyframes depending on what pictureN.swf you want shown. The movie is then loaded into the target MC (subMcHolder) if it has not already been loaded from frame 1, or just displays it if it has already loaded!

    Sam





  5. #5
    Junior Member
    Join Date
    Jul 2001
    Posts
    8
    Hey Sam,

    Thanks a lot for your insight...

    My main concern is technique, i.e what is the most elegant way to do this. There's always more then one way to do something.

    However, you have brought to my attention a technique which was not so obvious to me (loading swfs into different frames of the same mc and then simply moving to the desired frame).

    One question which comes to mind though...
    Would each frame have a seperate instance of mcHolder? so that they may be targetted from the first frame? or is it possible to use just one movieclip mcHolder instance in the main timeline?

    kind regards
    Sanjiv

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    Yeah, you need 12 separate frames, with 12 separate mcHolders inside your main timeline or a mainMcHolder

    Regards

    Sam

  7. #7
    Junior Member
    Join Date
    Jul 2001
    Posts
    8
    Thats great.
    Thanks for that
    Sanjiv.

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