A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Goto Frame with loadMovie

  1. #1
    Always Without Crutches!
    Join Date
    Feb 2005
    Location
    On The Interweb Thingy
    Posts
    44

    Goto Frame with loadMovie

    Hey Flashers...it's been a while since I've run into trouble but it was always gonna happen! I'm not much of an AS user to be honest...but this is one instance when I want to use it!

    Is it possible to use the loadMovie function and specify which frame the movie begins at? Basically, let us imagine, I'd like to have two buttons that load one swf file. One loads the movie at the beginning and the other on frame 10. Possible or not?

    Thanks in advance for the replies!!!

  2. #2
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231
    There are a few ways you can do it.
    One way is to leave the first frame of your external movie blank.
    Make each of the buttons set one variable to different values:
    button1_btn.onRelease = function(){
    _root.myVar = A;
    }

    button2_btn.onRelease = function(){
    _root.myVar = B;
    }

    Then, on the first from of the external swf, put a statement that checks to see which variable was set:
    if (_level0.myVar ==A){
    gotoAndPlay(2);
    }else if(_level0.myVar ==B){
    gotoAndPlay(20);
    }

    So the first thing that happens the moment the outside movie loads is that it checks to see which frame to start at.
    Now, this does not take into account how heavy the external movie is and whether or not you need a preloader. That's another story.

  3. #3
    Always Without Crutches!
    Join Date
    Feb 2005
    Location
    On The Interweb Thingy
    Posts
    44
    Thanks man for the fast response! That should do the trick perfectly...it's not going to be a huge file so a preloader shouldn't be required! I'll bodge in the AS now and it's happy days!

    Cheers Big 'Un!

  4. #4
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231
    Oh, and in case this isn't obvious, your buttons still need the loadMovie command. I left that out.


    button1_btn.onRelease = function(){
    _root.myVar = A;
    _root.empty_mc.loadMovie("external.swf");//or whatever...
    }
    Last edited by Big 'Un; 08-22-2006 at 02:21 PM.

  5. #5
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    create a new FLA. Save it with the name main.fla. Now, create an mc/btn. Drag 2 instances of it onto your main timeline (on frame 1)... give them the instance names 'btn0' and 'btn1' (without the quotes). create another layer (your ACTIONS layer) Then place this code on the actions layer, also in frame one:
    Code:
    var holder:MovieClip = this.createEmptyMovieClip("holder", 1);
    
    var myFrame:String;
    
    btn0.onRelease = function(){
    	holder.loadMovie("external.swf");
    	myFrame = "sect_2";
    }
    
    btn1.onRelease = function(){
    	holder.loadMovie("external.swf");
    	myFrame = "sect_1";
    }
    Save you movie again.

    Now create a new FLA. Save it to the same directory as main.fla but give it the name external.fla.

    Now, create 3 layers in your external.fla file : actions, labels, & stuff.
    Leave the first frame blank, except for this code in the actions layer
    Code:
    gotoAndStop(_level0.myFrame);
    Nn frame 2 (or wherever you like) create a keyframe in the 'labels' layer and give it the frame label "sect_1" (without quotes) and create a keyframe (on the same frame as in labels layer) in the 'stuff' layer and draw whatever you want.

    Move down the timeline a bit, and create a 2nd keyframe on both the 'labels' and 'stuff' layers... give the labels frame the name "sect_2", and draw whatever you want on the 'stuff' frame.

    Publish the external.fla file using Flash Player 7 and ActionScript 2.0 settings (or higher)....

    go back to your Main.fla and test the movie. when you press btn0, it will load the file to the second frame label, as specified in the code, and btn1, will load to the first frame label...
    Attached Files Attached Files
    Last edited by madzigian; 08-22-2006 at 02:32 PM.
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  6. #6
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231
    Yeah. I like madzigian's solution better. Similar concept but a little cleaner.

  7. #7
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    i attached an example if you need it.

    if you are loading files using a preloader... you'll need to make a few minor adjustments... but the changes are very simple and logical.
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  8. #8
    Always Without Crutches!
    Join Date
    Feb 2005
    Location
    On The Interweb Thingy
    Posts
    44
    Wow! Thanks.....I 'almost' understand that! I've used your file and it works like a dream...it's exactly what I wanted to do!!!

    The code you put in frame one in the main.fla file creates an empty holder for the swf to be loaded into, I've created a box (instance name 'loadbox') that is a specific size and in a certain area that I'd like the movie to be loaded into!

    One final thing...how do I make it load into a 'holder' that is already present!?

  9. #9
    Always Without Crutches!
    Join Date
    Feb 2005
    Location
    On The Interweb Thingy
    Posts
    44
    ......oh wait.....is it not easier to code in the size and the location of the 'holder' instead?!

  10. #10
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    i would suggest making your content the size you want it to be..... keep your empty 'holder' clip EMPTY. if you want to place a background behind your content, create a separate clip for the background, and place it behind the holder (on a lower layer).

    If you want to start manipulating the properties of your holder clip, I'd suggest using the MovieClipLoader() class to load your movies, and not loadMovie()

    you don't have to create the empty clip via actionscript either, i just did because it was quicker for my example. just go to INSERT --> New Symbol... --> MovieClip . name it empty_mc. then just close the clip (got back to main timeline) and drag an instance of the empty movie clip onto your stage. give it whatever instance name you want, and place it where you want. And every time you need an empty movie clip for something, just drag another instance of it onto your stage and give it a unique instance name.
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  11. #11
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    how do I make it load into a 'holder' that is already present!?
    to answer that.... you just target the clip you want to load your movie into. If it's instance name is my_mc for example.... you use my_mc.loadMovie("movei.swf')
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  12. #12
    Always Without Crutches!
    Join Date
    Feb 2005
    Location
    On The Interweb Thingy
    Posts
    44
    I've got it working like a treat now!

    Code:
    var myFrame:String;
    
    btn0.onRelease = function(){
    	loadbox.loadMovie("external.swf");
    	myFrame = "sect_1";
    }
    
    btn1.onRelease = function(){
    	loadbox.loadMovie("external.swf");
    	myFrame = "sect_2";
    }
    Thanks to both you and Big 'Un once again for helping me out! It's great to have such learned flashers out there on the interweb! No doubt I'll be back again with another problem at some point....but for now....job's a goodun!

    3B

  13. #13
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    good luck!
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

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