A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: [CS3] Load swf into another swf & jump to a frame

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    17

    [CS3] Load swf into another swf & jump to a frame

    Hi!

    I work with flash 2.0 CS3

    When I click a button I want to load/replace the swf with another swf and jump to a certain frame or label in the new swf. Is that possible? and if, can you please help me out with the code?

    Thanks a million/Tom

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    If you want one swf to completely replace another then the code is really simple. You'd use loadMovieNum

    loadMovieNum("myswf.swf",0);//replace myswf.swf with path to your swf
    gotoAndPlay(16);//replace 16 with the frame you want to play to.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Posts
    17
    Ok, but it dosen't work! Do you mean that I should paste that code on the action of the button?? It's a button that you click and then you go to the other swf.

  4. #4
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    give the button an instance name, lets say btn1 then on the timeline put
    PHP Code:
    btn1.onPress = function(){
    loadMovieNum("myswf.swf",0);//replace myswf.swf with path to your swf
    gotoAndPlay(16);//replace 16 with the frame you want to play to.

    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  5. #5
    Junior Member
    Join Date
    Jul 2008
    Location
    Jordan
    Posts
    2
    Hi,
    I want ask a qusetion if you please

    I worked with flipping book component to make my first book I made my book and put buttons, but I need to make Index of table to my book linking to reach to pages directly, I read I need to make my page as swf and I did that, and put buttons to reach the pages, but when I try to press buuton nothing happen, I don't know if I need to identify the swf page (table of index) in my main project and how???
    I tried to copy a button from table of index to main page in my project and the button is work, so I think I need to relation between swf (main project and Table of Index)
    My book contains 308 pages and my table of index 1 file swf .
    Note: the swf file is like a page from my book and the other pages are jpg files.

  6. #6
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    Mr_Brain, sounds like you've got yourself in a pickle. I might suggest going to the freelance forum and posting a job there for someone to complete. It may not even be that big a deal, but to pull apart another persons components or plugins and try to add something new if it is undocumented is a pain. Plus, with 308 files/pages that sounds like a lot of file transfer. Good luck with that.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  7. #7
    Junior Member
    Join Date
    Jul 2008
    Location
    Jordan
    Posts
    2
    Mr mneil thanks for replying me quickly,
    just I need:
    how can I activate the button from swf to another one, I mean: what the code if I want press button in first swf and the reaction happen in second swf.
    note the first swf become part of second swf???

  8. #8
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    it varies depending on how the other swf was loaded and where it is. If loaded by loadClip then you refer to the container mc it was loaded into ie:
    holder.myButton.onPress = function(){

    if it was loaded by loadMovie the same is true.

    If it was loaded by loadMovieNum then you have to target a level ie:
    _level3.myButton.onPress - function(){

    And, even still it may be more complicated than that if you're buttons are nested inside the loaded swf. And, then your function call is on the root and you have to target the appropriate place to load something new.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  9. #9
    Junior Member
    Join Date
    Jul 2008
    Posts
    17
    Quote Originally Posted by mneil
    give the button an instance name, lets say btn1 then on the timeline put
    PHP Code:
    btn1.onPress = function(){
    loadMovieNum("myswf.swf",0);//replace myswf.swf with path to your swf
    gotoAndPlay(16);//replace 16 with the frame you want to play to.

    It dosen.t work! It just starts from the begining in the new swf, it dosen't jump to the frame!

  10. #10
    Junior Member
    Join Date
    Jul 2008
    Posts
    2
    never it will work, flash doesn't jump through allien swf frames! If it did, you could get software to analyse all swf files frame by frame jumping around, also you could make link to any swf file on internet to your link or your button, sounds more like html, so forget html, think what is flash essence. Read on wiki, very good article about RIA (Rich Internet App).

  11. #11
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    If you use loadClip then you can do this just fine. It won't work with loadMovieNum to jump to the frame.

    PHP Code:
    this.createEmptyMovieClip("holder",this.getNextHighestDepth());
    var 
    mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);
    mcLoader.loadClip("mySwf.swf",holder);
    function 
    onLoadInit(target:MovieClip){
        
    target.gotoAndPlay(16);

    This is much different than the first example I showed you. The reason the first one doesn't work is because gotoAndPlay is firing before the new swf is loaded. Plus, the new swf is replacing the old. This new version uses a listener to wait to call gotoAndPlay and you are setting the new swf on top of the old swf.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  12. #12
    Junior Member
    Join Date
    Jul 2008
    Posts
    17
    Quote Originally Posted by mneil
    If you use loadClip then you can do this just fine. It won't work with loadMovieNum to jump to the frame.

    PHP Code:
    this.createEmptyMovieClip("holder",this.getNextHighestDepth());
    var 
    mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);
    mcLoader.loadClip("mySwf.swf",holder);
    function 
    onLoadInit(target:MovieClip){
        
    target.gotoAndPlay(16);

    This is much different than the first example I showed you. The reason the first one doesn't work is because gotoAndPlay is firing before the new swf is loaded. Plus, the new swf is replacing the old. This new version uses a listener to wait to call gotoAndPlay and you are setting the new swf on top of the old swf.

    Ok, now its loading "over" the old swf-file...I dont want the old in the background, is it possible?

  13. #13
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    in the swf that is loading, create a new layer on the bottom of the timeline and make a square that has the color of the background to cover up everything in the old file that is underneath.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  14. #14
    Junior Member
    Join Date
    Jul 2008
    Posts
    17
    Ok, the background worked, but when I place the code in the beginning of the timline as you said it jumps directly to the swf, I want it to happen when I click a button, remember?

    Quote Originally Posted by mneil
    in the swf that is loading, create a new layer on the bottom of the timeline and make a square that has the color of the background to cover up everything in the old file that is underneath.

  15. #15
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    I want a million dollars. I've given you code for a button, I've given you code to load the movie and skip to another frame. Put them together.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  16. #16
    Junior Member
    Join Date
    Jul 2008
    Posts
    17
    errrm...no, you gave me several different things that I thought didn't match. But I solved it on my own. Thanks anyway.

    Quote Originally Posted by mneil
    I want a million dollars. I've given you code for a button, I've given you code to load the movie and skip to another frame. Put them together.

  17. #17
    Junior Member
    Join Date
    Dec 2008
    Posts
    4
    Quote Originally Posted by tomtom1977
    errrm...no, you gave me several different things that I thought didn't match. But I solved it on my own. Thanks anyway.
    Hi TomTom,
    Can I ask what you did? I tried following the script suggestions above but have not been able to put it together into a fuctioning script. I want to achieve the same goal: user clicks a button, new swf loads going to a specific frame label. Also using CS3/2.0.

    Thanks.

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