ActiveDen

Controlling the timeline of an swf loaded in with loadMovie

381 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
  • Netherlands
  • Referred between 50 and 99 users
Yvo says

Hi guys, this might have been asked and answered before, but don’t know exactly what to look for in the forum. I want to know if it is possible to control the timeline of an external swf loaded in with loadMovie.

Example: Let’s say I have a main file in which I have 2 button mc’s with instance names btn1 and btn2. I have a holder mc on which I can load my swf. Let’s call that external.swf. This external swf has a stop command in frame 1 and in that last frame of its timeline.

When I press btn1 I want it to load in the external.swf onto the holder just using the loadMovie command. Nothing difficult here of course. When it is loaded in it stays on frame 1 due to the stop command in frame 1. I want the external.swf to start going to frame 2 (and thus start playing until the last frame) when I press btn2. Is this possible? And if so, how?

4 years ago
6471 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • United Kingdom
  • Referred between 10 and 49 users
MSFX says

I know this is do-able as I do it all the time but in AS3 , not AS2 …

Once you have stored it to your holder variable maybe try this

holder.externalSWF.gotoAndPlay(2);

In AS3 i’d use:

// store loaded content
swf = MovieClip(e.currentTarget.content)

swf.gotoAndPlay(2);

easy :D

4 years ago
MSFX is a moderator
6471 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • United Kingdom
  • Referred between 10 and 49 users
MSFX says

come to think of it there was a file not that long ago that allowed to go scroll through the frames of a loaded swf, maybe have a quick search for that, within the last week or so I think…

4 years ago
MSFX is a moderator
3359 posts
  • Has been a member for 5-6 years
  • Author had a File in an Envato Bundle
  • Interviewed on the Envato Notes blog
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 100 and 499 items
  • South Africa
  • Referred between 500 and 999 users
digitalscience says

Yvo, this is the code for AS2 :

btn2.onPress = function() {
    holder.gotoAndPlay(2);
};
4 years ago
607 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Bought between 10 and 49 items
  • India
  • Referred between 1 and 9 users
sanju1979 says
Yvo, this is the code for AS2 :
 btn2.onPress = function() { holder.gotoAndPlay(2); }; 

sorry digital science thats incorrect MSFX is correct

so it wil be like

yourbutton.onPress = function() { _root.yourholderinmainmovie.yourexternalswffile.gotoAndplay(2); }

thanks

4 years ago
3359 posts
  • Has been a member for 5-6 years
  • Author had a File in an Envato Bundle
  • Interviewed on the Envato Notes blog
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 100 and 499 items
  • South Africa
  • Referred between 500 and 999 users
digitalscience says
Yvo, this is the code for AS2 :
 btn2.onPress = function() { holder.gotoAndPlay(2); }; 

sorry digital science thats incorrect MSFX is correct

so it wil be like

yourbutton.onPress = function() { _root.yourholderinmainmovie.yourexternalswffile.gotoAndplay(2); }

thanks

wrong :P when you load a swf into a holder movieclip, the name of the swf root is the holder instance name. In your code – how exactly do you get the instance name of yourexternalswffile ?? Because when u load a swf you can only identify it by the level or movieclip it’s loaded into.

4 years ago
6471 posts
  • Has been a member for 4-5 years
  • Won a Competition
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Beta Tester
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • United Kingdom
  • Referred between 10 and 49 users
MSFX says
Yvo, this is the code for AS2 :
 btn2.onPress = function() { holder.gotoAndPlay(2); }; 
sorry digital science thats incorrect MSFX is correct

YEAH !! 8)

but no lol :p

DS is right, when you load an external SWF into Flash as it is actually an Instance of the Timeline, and therefore you cannot give it a name…

This gave me an initial headache in AS3 but then I worked it out…

var swf:MovieClip;
var swfHolder:MovieClip;

// once swf has loaded, in your Event.COMPLETE function

swfHolder = MovieClip(e.currentTarget.content);

swf = new MovieClip();
swf.addChild(swfHolder);
swf.name = "whateverNameHere";

If I had tried to name the swfHolder instance I would get a compiler error or run time, cant remember which… :D

4 years ago
MSFX is a moderator
381 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
  • Netherlands
  • Referred between 50 and 99 users
Yvo says

Thanks very much for the effort guys!!! I’ll give it a try.

4 years ago
279 posts
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Netherlands
  • Referred between 10 and 49 users
FonZ says

First off, don’t use the loadMovie command. It sucks.

use something like this:

//** //Function to load a clip or picture //** function theLoader(loadUrl, loadHold) { //flip our loadStat loadStat = true; //create a new loader object var mcLoader:MovieClipLoader = new MovieClipLoader(); //create a new listener object var mcListener:Object = new Object(); //function to give a visual representation of the loading progress //on load init mcListener.onLoadInit = function(target:MovieClip) { //flip the load track variable loadStat = false; //if there is a next function, trigger it nextFunc(); //clear the trigger nextFunc = nada; }; //add a movieclip loader mcLoader.addListener(mcListener); }

//load the clip
mcLoader.loadClip(loadUrl, loadHold);

What you would do is create a holder (which you did), have an external file (which you have) and simply call the function

theLoader(“myswf.swf”, holderMc);

How does this help? Well NOT .. But it gives you a. more control over loading (maybe check the loadStat) b. an option to directly work on the clip once loaded, by adding instructions at the onLoadInit. There you could state, loadHold.gotoAndStop(1); or you could trigger a function like myFunction(loadHold) and the instance name gets passed without any problems.

If you keep running into trouble, add trace(loadHold._name) to the onLoadInit and it will display the name of the holder (DS is correct)..

you should basicly only use loadMovie when you don’t want to control, modify or whatever.

good luck

4 years ago
381 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
  • Netherlands
  • Referred between 50 and 99 users
Yvo says

I know my question might sound like I’m a beginner, but I’m not. I was just wondering if it is possible, cause I’m trying something. I used loadMovie in my file, cause I did not need to have control over the loading. Just a very simple load in of an swf.

When making a gallery or something like that, I always use the movieClipLoader class, so I can use preloaders for images. Cheers for the help Fonz, but I was already aware of loading in images this way. ;)

4 years ago
by
by
by
by
by