<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: How to Tell When an External SWF has Fully Loaded</title>
	<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded</link>
	<description>Luck is the residue of good design.</description>
	<pubDate>Fri, 12 Mar 2010 04:08:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-393132</link>
		<pubDate>Tue, 19 May 2009 14:37:16 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-393132</guid>
					<description>Flash Duniya,

The reason your code works when you test locally is because the external SWF (card.swf) is already present on your hard drive during the test.  When you upload these files to the server, there's a good chance you're clicking the &lt;code&gt;btn&lt;/code&gt; button before card.swf has fully loaded.  This is why you'll need something like the techniques shown in the article above.  It would be useful, for example, if you hid and disabled the button by default (&lt;code&gt;btn._visible = false;&lt;/code&gt; and &lt;code&gt;btn.enabled = false;&lt;/code&gt;), then revealed and re-enabled the button when card.swf is fully loaded.</description>
		<content:encoded><![CDATA[<p>Flash Duniya,</p>
<p>The reason your code works when you test locally is because the external SWF (card.swf) is already present on your hard drive during the test.  When you upload these files to the server, there&#8217;s a good chance you&#8217;re clicking the <code>btn</code> button before card.swf has fully loaded.  This is why you&#8217;ll need something like the techniques shown in the article above.  It would be useful, for example, if you hid and disabled the button by default (<code>btn._visible = false;</code> and <code>btn.enabled = false;</code>), then revealed and re-enabled the button when card.swf is fully loaded.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Flash Duniya</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-393131</link>
		<pubDate>Tue, 19 May 2009 14:27:29 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-393131</guid>
					<description>container.loadMovie(&quot;http://flashduniya.com/images/card.swf&quot;)

btn.onPress = function() {
	container.gotoAndStop(5);
};

It's working fine, but while we upload this to any server then it's not working. Can you plz tell me the solution of that?</description>
		<content:encoded><![CDATA[<p>container.loadMovie(&#8221;http://flashduniya.com/images/card.swf&#8221;)</p>
<p>btn.onPress = function() {<br />
	container.gotoAndStop(5);<br />
};</p>
<p>It&#8217;s working fine, but while we upload this to any server then it&#8217;s not working. Can you plz tell me the solution of that?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-90867</link>
		<pubDate>Sun, 14 Oct 2007 00:06:28 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-90867</guid>
					<description>Rosieman,

I sounds like you've probably checked the documentation already, but for sake of completeness, &lt;code&gt;loadClip()&lt;/code&gt; returns &quot;&lt;code&gt;true&lt;/code&gt; if the URL request was sent successfully; otherwise &lt;code&gt;false&lt;/code&gt;.&quot;  So theoretically something about your request is going batty, and security settings would probably be among the first things to come to my mind, too &amp;#8212; outside of double- and triple-checking that the requested file is located where it should be &amp;#8212; and you've already checked security settings.

I've used &lt;code&gt;MovieClipLoader&lt;/code&gt; instances in plenty of constructors without issue, so its placement in your constructor function shouldn't be a problem.  Not 100% sure what you mean by &quot;instantiated from the Actions panel of an FLVPlayback component,&quot; though.  Are you attaching code directly to your component?  That &lt;em&gt;shouldn't&lt;/em&gt; be a problem, although I encourage you to give your component an instance name and keep all your ActionScript in keyframes.

&lt;blockquote&gt;Does this need to be called from a clip that’s explicitly placed on the stage somewhere?&lt;/blockquote&gt;

As long as your &lt;code&gt;MovieClipLoader&lt;/code&gt; instance is valid, it really shouldn't matter where you end up referencing it from.  I personally tend to keep most of my code in a single layer of the main timeline (or in external class files) ... something about your mention of &quot;called from a clip&quot; makes me think you're attaching most of your code directly to objects, but maybe you're talking about keyframe code inside a nested clip.  Either which way, none of it &lt;em&gt;should&lt;/em&gt; matter, and I'm afraid nothing leaps out at me immediately as an error on your part, given your description so far.</description>
		<content:encoded><![CDATA[<p>Rosieman,</p>
<p>I sounds like you&#8217;ve probably checked the documentation already, but for sake of completeness, <code>loadClip()</code> returns &#8220;<code>true</code> if the URL request was sent successfully; otherwise <code>false</code>.&#8221;  So theoretically something about your request is going batty, and security settings would probably be among the first things to come to my mind, too &mdash; outside of double- and triple-checking that the requested file is located where it should be &mdash; and you&#8217;ve already checked security settings.</p>
<p>I&#8217;ve used <code>MovieClipLoader</code> instances in plenty of constructors without issue, so its placement in your constructor function shouldn&#8217;t be a problem.  Not 100% sure what you mean by &#8220;instantiated from the Actions panel of an FLVPlayback component,&#8221; though.  Are you attaching code directly to your component?  That <em>shouldn&#8217;t</em> be a problem, although I encourage you to give your component an instance name and keep all your ActionScript in keyframes.</p>
<blockquote><p>Does this need to be called from a clip that’s explicitly placed on the stage somewhere?</p></blockquote>
<p>As long as your <code>MovieClipLoader</code> instance is valid, it really shouldn&#8217;t matter where you end up referencing it from.  I personally tend to keep most of my code in a single layer of the main timeline (or in external class files) &#8230; something about your mention of &#8220;called from a clip&#8221; makes me think you&#8217;re attaching most of your code directly to objects, but maybe you&#8217;re talking about keyframe code inside a nested clip.  Either which way, none of it <em>should</em> matter, and I&#8217;m afraid nothing leaps out at me immediately as an error on your part, given your description so far.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Rosieman</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-90820</link>
		<pubDate>Sat, 13 Oct 2007 18:51:55 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-90820</guid>
					<description>Any idea what would cause MovieClipLoader.loadClip to return false?  I've checked security settings, moved this call out of a constructor.  I'm calling this from an AS object that's instantiated from the Actions panel of an FLVPlayback component.  Does this need to be called from a clip that's explicitly placed on the stage somewhere?

For the life of me, I can't figure this one out...

Thanks!</description>
		<content:encoded><![CDATA[<p>Any idea what would cause MovieClipLoader.loadClip to return false?  I&#8217;ve checked security settings, moved this call out of a constructor.  I&#8217;m calling this from an AS object that&#8217;s instantiated from the Actions panel of an FLVPlayback component.  Does this need to be called from a clip that&#8217;s explicitly placed on the stage somewhere?</p>
<p>For the life of me, I can&#8217;t figure this one out&#8230;</p>
<p>Thanks!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76695</link>
		<pubDate>Wed, 29 Aug 2007 17:22:11 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76695</guid>
					<description>Denise,

Glad to hear it!  :)  Yeah, there are a handful of ways to handle events in ActionScript 2.0.  AS3 simplifies that (in most cases) to a single approach.  In this case, &lt;code&gt;onLoadComplete&lt;/code&gt; may work just as well; it's just that &lt;code&gt;onLoadInit&lt;/code&gt; not only waits for the external SWF to load, it also waits for any code (if available) in the first frame of the loaded SWF to execute.</description>
		<content:encoded><![CDATA[<p>Denise,</p>
<p>Glad to hear it!  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Yeah, there are a handful of ways to handle events in ActionScript 2.0.  AS3 simplifies that (in most cases) to a single approach.  In this case, <code>onLoadComplete</code> may work just as well; it&#8217;s just that <code>onLoadInit</code> not only waits for the external SWF to load, it also waits for any code (if available) in the first frame of the loaded SWF to execute.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denise Myers</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76693</link>
		<pubDate>Wed, 29 Aug 2007 17:10:51 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76693</guid>
					<description>It works!  I didn't know to use the MovieClipLoader.onLoadInit event handler. Thanks a million!</description>
		<content:encoded><![CDATA[<p>It works!  I didn&#8217;t know to use the MovieClipLoader.onLoadInit event handler. Thanks a million!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76426</link>
		<pubDate>Tue, 28 Aug 2007 17:51:04 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76426</guid>
					<description>Denise,

&lt;blockquote&gt;It seems the key is comparing current to total frames on the loaded movie, NOT the loader mc.&lt;/blockquote&gt;

That depends on the nature of the loaded content.  I haven't experimented with Captivate personally, but my hunch is that it outputs SWFs in a non-linear fashion.  (Don't quote me on this ... just a hunch.)  If Captivate SWFs are nested at all &amp;#8212; and I think this is likely &amp;#8212; you may indeed have to dig a level deeper, which is leading you in the direction you're thinking.

In actual practice, the loader movie clip, in a sense, &lt;em&gt;becomes&lt;/em&gt; the loaded content.

&lt;pre&gt;&lt;code&gt;var mc:MovieClip = this.createEmptyMovieClip(&quot;loader&quot;, 0);

var mcl:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function():Void {
  mc.onEnterFrame = function():Void {
    trace(mc._currentframe + &quot; of &quot; + mc._totalframes);
  }
}
mcl.addListener(listener);

mcl.loadClip(&quot;loadMe.swf&quot;, mc);&lt;/code&gt;&lt;/pre&gt;

The first line creates my loader clip (though this could have been an empty movie clip symbol dragged by hand to the stage and given an instance name.

The middle portion instantiates &lt;code&gt;MovieClipLoader&lt;/code&gt; and an &lt;code&gt;Object&lt;/code&gt; instance and prepares the way for a &lt;code&gt;MovieClipLoader.onLoadInit&lt;/code&gt; event handler.  As you can see, we'll be tracing the &lt;code&gt;MovieClip_currentframe&lt;/code&gt; and &lt;code&gt;_totalframes&lt;/code&gt; properties of the container clip, referenced by its the &lt;code&gt;mc&lt;/code&gt; variable (could just as easily be its instance name, &lt;code&gt;loader&lt;/code&gt;).

The final line loads the external SWF into the loader clip.  The output I get is this:

2 of 40
3 of 40
4 of 40
5 of 40
6 of 40
7 of 40
8 of 40
9 of 40
10 of 40
11 of 40
// etc.

... which, interestingly, skips the first frame &amp;#8212; but nonetheless picks up, as expected, in recounting the frames of the loaded content (not the loader clip).

In your situation, the actual multi-framed content must be nestled in a container clip within the Captivate SWF's main timeline.  Even if you're able to drill down to something that contains a timeline of some length, I'm not entirely sure the timeline you find will necessarily represent the full extent of the SWF's animation.</description>
		<content:encoded><![CDATA[<p>Denise,</p>
<blockquote><p>It seems the key is comparing current to total frames on the loaded movie, NOT the loader mc.</p></blockquote>
<p>That depends on the nature of the loaded content.  I haven&#8217;t experimented with Captivate personally, but my hunch is that it outputs SWFs in a non-linear fashion.  (Don&#8217;t quote me on this &#8230; just a hunch.)  If Captivate SWFs are nested at all &mdash; and I think this is likely &mdash; you may indeed have to dig a level deeper, which is leading you in the direction you&#8217;re thinking.</p>
<p>In actual practice, the loader movie clip, in a sense, <em>becomes</em> the loaded content.</p>
<pre><code>var mc:MovieClip = this.createEmptyMovieClip("loader", 0);

var mcl:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function():Void {
  mc.onEnterFrame = function():Void {
    trace(mc._currentframe + " of " + mc._totalframes);
  }
}
mcl.addListener(listener);

mcl.loadClip("loadMe.swf", mc);</code></pre>
<p>The first line creates my loader clip (though this could have been an empty movie clip symbol dragged by hand to the stage and given an instance name.</p>
<p>The middle portion instantiates <code>MovieClipLoader</code> and an <code>Object</code> instance and prepares the way for a <code>MovieClipLoader.onLoadInit</code> event handler.  As you can see, we&#8217;ll be tracing the <code>MovieClip_currentframe</code> and <code>_totalframes</code> properties of the container clip, referenced by its the <code>mc</code> variable (could just as easily be its instance name, <code>loader</code>).</p>
<p>The final line loads the external SWF into the loader clip.  The output I get is this:</p>
<p>2 of 40<br />
3 of 40<br />
4 of 40<br />
5 of 40<br />
6 of 40<br />
7 of 40<br />
8 of 40<br />
9 of 40<br />
10 of 40<br />
11 of 40<br />
// etc.</p>
<p>&#8230; which, interestingly, skips the first frame &mdash; but nonetheless picks up, as expected, in recounting the frames of the loaded content (not the loader clip).</p>
<p>In your situation, the actual multi-framed content must be nestled in a container clip within the Captivate SWF&#8217;s main timeline.  Even if you&#8217;re able to drill down to something that contains a timeline of some length, I&#8217;m not entirely sure the timeline you find will necessarily represent the full extent of the SWF&#8217;s animation.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denise Myers</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76415</link>
		<pubDate>Tue, 28 Aug 2007 17:19:37 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-76415</guid>
					<description>David,

Thanks for your response -- that explains why swapDepths doesn't work!  I'm still not getting this to work however. It seems the key is comparing current to total frames on the loaded movie, NOT the loader mc.  I've tried the following 3 methods:

loadMovie: When I compare the _currentframe &amp;#38; _totalframes properties on the movie clip that contains the loaded content, it's finding a match from frame 1 because it's referencing those properties on the loader movie clip which only has 1 frame. 

loadMovieNum: Here I was able to reference the timeline of the loaded movie by the level number -- this worked great other than the problem with the buttons being behind the movie.  

MovieClipLoader:  Used on the name given to the loaded movie, I get this error &quot;There is no property with the name '_currentframe'.&quot;  Once again if I reference the loader mc, I get a match at frame 1. 

In case you're wondering, I'm trying to get this to work because I'm loading multiple existing swfs created by &quot;Captivate&quot; and need to flag the end of each movie with an fscommand in order to enable the user to go on to the next movie.</description>
		<content:encoded><![CDATA[<p>David,</p>
<p>Thanks for your response &#8212; that explains why swapDepths doesn&#8217;t work!  I&#8217;m still not getting this to work however. It seems the key is comparing current to total frames on the loaded movie, NOT the loader mc.  I&#8217;ve tried the following 3 methods:</p>
<p>loadMovie: When I compare the _currentframe &amp; _totalframes properties on the movie clip that contains the loaded content, it&#8217;s finding a match from frame 1 because it&#8217;s referencing those properties on the loader movie clip which only has 1 frame. </p>
<p>loadMovieNum: Here I was able to reference the timeline of the loaded movie by the level number &#8212; this worked great other than the problem with the buttons being behind the movie.  </p>
<p>MovieClipLoader:  Used on the name given to the loaded movie, I get this error &#8220;There is no property with the name &#8216;_currentframe&#8217;.&#8221;  Once again if I reference the loader mc, I get a match at frame 1. </p>
<p>In case you&#8217;re wondering, I&#8217;m trying to get this to work because I&#8217;m loading multiple existing swfs created by &#8220;Captivate&#8221; and need to flag the end of each movie with an fscommand in order to enable the user to go on to the next movie.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-75926</link>
		<pubDate>Mon, 27 Aug 2007 00:53:52 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-75926</guid>
					<description>Denise,

Assuming the loaded content is linear &amp;#8212; that is, it has visually or conceptually reached its end when its timeline has run its course &amp;#8212; then yes, a comparison of the &lt;code&gt;MovieClip._currentframe&lt;/code&gt; and &lt;code&gt;MovieClip._totalframes&lt;/code&gt; properties is a great way to determine when the loaded content has finished playing.  The key in that scenario is the comparison, as you've shown, and actually has nothing to do with the mechanism used to load the content (could be &lt;code&gt;loadMovie()&lt;/code&gt;, &lt;code&gt;loadMovieNum()&lt;/code&gt;, &lt;code&gt;MovieClip.loadMovie()&lt;/code&gt;, the &lt;code&gt;MovieClipLoader&lt;/code&gt; class, or anything else that loads a SWF into a timeline).  The &lt;code&gt;loadMovieNum()&lt;/code&gt; function is a somewhat dated approach, and it loads content into a level rather than a movie clip symbol, but even so ... levels are just stacked documents played by Flash Player:  in the end, even they are simply movie clips, just like the main timeline is a movie clip.  (Actually, they're just &lt;em&gt;other&lt;/em&gt; main timelines.  &lt;code&gt;_level0&lt;/code&gt; is the default main timeline, and &lt;code&gt;_level1&lt;/code&gt; has its own main timeline, and so on.)

The reason you can't get your control buttons to appear over your other content is almost certainly because your buttons are in &lt;code&gt;_level0&lt;/code&gt;, whose content can never appear in levels that are sequentially higher than it.  The &lt;code&gt;MovieClip.swapDepths()&lt;/code&gt; method only works with movie clips that share the same parent timeline &amp;#8212; and these don't.  Consider using &lt;code&gt;MovieClip.loadMovie()&lt;/code&gt; &amp;#8212; or better, the &lt;code&gt;MovieClipLoader&lt;/code&gt; class &amp;#8212; and use the same &lt;code&gt;_currentframe&lt;/code&gt; and &lt;code&gt;_totalframes&lt;/code&gt; properties on whatever timeline (movie clip) contains the loaded content.  By keeping your loaded content in the same level as your buttons, you'll be able to use &lt;code&gt;swapDepths()&lt;/code&gt; on them, assuming they both appear in the same timeline (e.g., your buttons and the container are both in the main timeline, or both nested in the same movie clip).  Or you could simply sidestep the need to swap by ensuring that your buttons appear in a higher layer of the main timeline than the container clip into which your loaded content appears.</description>
		<content:encoded><![CDATA[<p>Denise,</p>
<p>Assuming the loaded content is linear &mdash; that is, it has visually or conceptually reached its end when its timeline has run its course &mdash; then yes, a comparison of the <code>MovieClip._currentframe</code> and <code>MovieClip._totalframes</code> properties is a great way to determine when the loaded content has finished playing.  The key in that scenario is the comparison, as you&#8217;ve shown, and actually has nothing to do with the mechanism used to load the content (could be <code>loadMovie()</code>, <code>loadMovieNum()</code>, <code>MovieClip.loadMovie()</code>, the <code>MovieClipLoader</code> class, or anything else that loads a SWF into a timeline).  The <code>loadMovieNum()</code> function is a somewhat dated approach, and it loads content into a level rather than a movie clip symbol, but even so &#8230; levels are just stacked documents played by Flash Player:  in the end, even they are simply movie clips, just like the main timeline is a movie clip.  (Actually, they&#8217;re just <em>other</em> main timelines.  <code>_level0</code> is the default main timeline, and <code>_level1</code> has its own main timeline, and so on.)</p>
<p>The reason you can&#8217;t get your control buttons to appear over your other content is almost certainly because your buttons are in <code>_level0</code>, whose content can never appear in levels that are sequentially higher than it.  The <code>MovieClip.swapDepths()</code> method only works with movie clips that share the same parent timeline &mdash; and these don&#8217;t.  Consider using <code>MovieClip.loadMovie()</code> &mdash; or better, the <code>MovieClipLoader</code> class &mdash; and use the same <code>_currentframe</code> and <code>_totalframes</code> properties on whatever timeline (movie clip) contains the loaded content.  By keeping your loaded content in the same level as your buttons, you&#8217;ll be able to use <code>swapDepths()</code> on them, assuming they both appear in the same timeline (e.g., your buttons and the container are both in the main timeline, or both nested in the same movie clip).  Or you could simply sidestep the need to swap by ensuring that your buttons appear in a higher layer of the main timeline than the container clip into which your loaded content appears.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denise Myers</title>
		<link>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-75367</link>
		<pubDate>Fri, 24 Aug 2007 21:10:26 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded#comment-75367</guid>
					<description>I have a problem not exactly the same as this topic, but maybe kind of related. I need to tell when the loaded swf is finished playing.  I couldn't find a way to make it work by loading the swf into a Movie Clip, but I did get it to work by using loadMovieNum --

onEnterFrame = function () {
	if (_level1._framesloaded != undefined &amp;#38;&amp;#38; _level1._currentframe == _level1._totalframes) {
		control.Text = &quot;Press continue to move on.&quot;;
	}
};

My problem now is that I can't get my control buttons to go in front of the loaded movie.  I tried swapDepths to no avail.  Any ideas on either making the loadMovie method work, or moving the depth of my control bar movie clip above the loaded movie?</description>
		<content:encoded><![CDATA[<p>I have a problem not exactly the same as this topic, but maybe kind of related. I need to tell when the loaded swf is finished playing.  I couldn&#8217;t find a way to make it work by loading the swf into a Movie Clip, but I did get it to work by using loadMovieNum &#8211;</p>
<p>onEnterFrame = function () {<br />
	if (_level1._framesloaded != undefined &amp;&amp; _level1._currentframe == _level1._totalframes) {<br />
		control.Text = &#8220;Press continue to move on.&#8221;;<br />
	}<br />
};</p>
<p>My problem now is that I can&#8217;t get my control buttons to go in front of the loaded movie.  I tried swapDepths to no avail.  Any ideas on either making the loadMovie method work, or moving the depth of my control bar movie clip above the loaded movie?
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
