

































<?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: Loading and Tracking Multiple Files at the Same Time (Part 1)</title>
	<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1</link>
	<description>Luck is the residue of good design.</description>
	<pubDate>Wed, 08 Feb 2012 15:12:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Tom Anderson</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-355696</link>
		<pubDate>Thu, 26 Feb 2009 12:32:32 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-355696</guid>
					<description>FYI I meant to type in the last code section

myInstance.runAnotherFunction();</description>
		<content:encoded><![CDATA[<p>FYI I meant to type in the last code section</p>
<p>myInstance.runAnotherFunction();
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Tom Anderson</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-355694</link>
		<pubDate>Thu, 26 Feb 2009 12:27:41 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-355694</guid>
					<description>This article helped me to resolve a key point about listeners in general. It seems that listeners in a class file cannot always access the other information in that same class file. By passing the instance of that class along with the message, we can get that access.

I've been struggling this for a while, so I'm really glad I found this site.

For example, we declare

class myClass
{
  var Listener:Object;
  function myClass()
  {
    myListener:Object = new Object();
    _global.Broadcaster.addListener(myListener);
    myListener.anyMessage = function()
    {
      trace(&quot;this message can be read&quot;);
       runAnotherFunction();
    }
   } // end myClass

  runAnotherFunction = function()
  {
    trace(&quot;this message is inaccessible&quot;);
  }
}


For this code, the function runAnotherFunction will never be called, even if we broadcast a message that myListener registers!

Instead, I learned that I could pass in the instance to the instance in the message. This modification will work, if we broadcast the instance of the class that we declared with var myInstance:myClass = new myClass:
_global.Broadcaster.broadcastMessage(&quot;anyMessage&quot;, myInstance);

    myListener.anyMessage = function(myInstance)
    {
      trace(&quot;this message can be read&quot;);
       myThis.runAnotherFunction();
    }


One question remains: How about declaring the type of myInstance? I thought you weren't supposed to use an instance of a class inside the declaration of the class itself. SO, this means that the listener is actually not running as part of the class, but is a more global, and may explain why listeners don't have any _parent.

I really liked this article. Thanks!</description>
		<content:encoded><![CDATA[<p>This article helped me to resolve a key point about listeners in general. It seems that listeners in a class file cannot always access the other information in that same class file. By passing the instance of that class along with the message, we can get that access.</p>
<p>I&#8217;ve been struggling this for a while, so I&#8217;m really glad I found this site.</p>
<p>For example, we declare</p>
<p>class myClass<br />
{<br />
  var Listener:Object;<br />
  function myClass()<br />
  {<br />
    myListener:Object = new Object();<br />
    _global.Broadcaster.addListener(myListener);<br />
    myListener.anyMessage = function()<br />
    {<br />
      trace(&#8221;this message can be read&#8221;);<br />
       runAnotherFunction();<br />
    }<br />
   } // end myClass</p>
<p>  runAnotherFunction = function()<br />
  {<br />
    trace(&#8221;this message is inaccessible&#8221;);<br />
  }<br />
}</p>
<p>For this code, the function runAnotherFunction will never be called, even if we broadcast a message that myListener registers!</p>
<p>Instead, I learned that I could pass in the instance to the instance in the message. This modification will work, if we broadcast the instance of the class that we declared with var myInstance:myClass = new myClass:<br />
_global.Broadcaster.broadcastMessage(&#8221;anyMessage&#8221;, myInstance);</p>
<p>    myListener.anyMessage = function(myInstance)<br />
    {<br />
      trace(&#8221;this message can be read&#8221;);<br />
       myThis.runAnotherFunction();<br />
    }</p>
<p>One question remains: How about declaring the type of myInstance? I thought you weren&#8217;t supposed to use an instance of a class inside the declaration of the class itself. SO, this means that the listener is actually not running as part of the class, but is a more global, and may explain why listeners don&#8217;t have any _parent.</p>
<p>I really liked this article. Thanks!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-138458</link>
		<pubDate>Sat, 23 Feb 2008 02:11:54 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-138458</guid>
					<description>Annie,

Looks like part of your code got cut off, but I think the answer to your question lies in &lt;a href=&quot;http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;part 2 of this tutorial&lt;/a&gt;.

You'll see an &lt;code&gt;onGroupProgress&lt;/code&gt; event that tells you &lt;code&gt;groupBytesLoaded&lt;/code&gt; and &lt;code&gt;groupBytesTotal&lt;/code&gt; values for the whole group of clips/images.  I think that should do it for you, but let me know if that doesn't make sense, okay?</description>
		<content:encoded><![CDATA[<p>Annie,</p>
<p>Looks like part of your code got cut off, but I think the answer to your question lies in <a href="http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2" target="_blank" rel="nofollow">part 2 of this tutorial</a>.</p>
<p>You&#8217;ll see an <code>onGroupProgress</code> event that tells you <code>groupBytesLoaded</code> and <code>groupBytesTotal</code> values for the whole group of clips/images.  I think that should do it for you, but let me know if that doesn&#8217;t make sense, okay?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: annie</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-131232</link>
		<pubDate>Sat, 09 Feb 2008 02:48:39 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-131232</guid>
					<description>Hi David,

I keep coming back to your website...great as usual :)

I was just wondering if there's a way to perform an action only after all of the clips/images associated with a MovieClipLoader have been loaded.  Here's what I'm doing now - using a counter - but maybe there's an easier way?  Say for example I want to order a set of variable-sized images once they've all loaded.


&lt;code&gt;
class gallery() {
   private var galleryMC:MovieClip;
   private var images:Array;
   private var numImagesLoaded:Number;

   function gallery() {
        galleryMC = _root.createEmptyMovieClip(&quot;myGalleryMovieClip&quot;, _root.getNextHighestDepth());
        images = [&quot;1.jpg&quot;, &quot;2.jpg&quot;, &quot;3.jpg&quot;, &quot;4.jpg&quot;];
    		numImagesLoaded = 0;
    		
    		var gall = this;
		
    		//load images and center
    		var mcl:MovieClipLoader = new MovieClipLoader();
    		var listener:Object = new Object();
    		listener.onLoadInit = function(mc:MovieClip):Void {
    		   gall.numImagesLoaded++;
    		   if(gall.numImagesLoaded == gall.images.length - 1) {
    		        gall.orderGallery();
    		   }
    		}
    		mcl.addListener(listener);
		
		    //load all the images
    		for (var i=0; i


Thanks,
Annie</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>I keep coming back to your website&#8230;great as usual <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was just wondering if there&#8217;s a way to perform an action only after all of the clips/images associated with a MovieClipLoader have been loaded.  Here&#8217;s what I&#8217;m doing now - using a counter - but maybe there&#8217;s an easier way?  Say for example I want to order a set of variable-sized images once they&#8217;ve all loaded.</p>
<p><code><br />
class gallery() {<br />
   private var galleryMC:MovieClip;<br />
   private var images:Array;<br />
   private var numImagesLoaded:Number;</p>
<p>   function gallery() {<br />
        galleryMC = _root.createEmptyMovieClip("myGalleryMovieClip", _root.getNextHighestDepth());<br />
        images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"];<br />
    		numImagesLoaded = 0;</p>
<p>    		var gall = this;</p>
<p>    		//load images and center<br />
    		var mcl:MovieClipLoader = new MovieClipLoader();<br />
    		var listener:Object = new Object();<br />
    		listener.onLoadInit = function(mc:MovieClip):Void {<br />
    		   gall.numImagesLoaded++;<br />
    		   if(gall.numImagesLoaded == gall.images.length - 1) {<br />
    		        gall.orderGallery();<br />
    		   }<br />
    		}<br />
    		mcl.addListener(listener);</p>
<p>		    //load all the images<br />
    		for (var i=0; i</p>
<p>Thanks,<br />
Annie
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-124998</link>
		<pubDate>Mon, 28 Jan 2008 02:57:15 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-124998</guid>
					<description>Chuck,

Create an &lt;code&gt;Array&lt;/code&gt; instance to store your references:

&lt;code&gt;var containers:Array = new Array(clip1_mc, clip2_mc, clip3_mc, clip4_mc);&lt;/code&gt;

Now you have an array (a list, basically) that contains the instance names to your movie clips.  You can call the variable what you like, but I chose &lt;code&gt;containers&lt;/code&gt; because that's the role these movie clips play &amp;#8212; they're containers for your images.

Next, refer to the &quot;Jump Randomly&quot; article I linked to before to find the custom &lt;code&gt;shuffle()&lt;/code&gt; function.  Use that function to re-arrange the elements of your &lt;code&gt;containers&lt;/code&gt; array.  Now that they've been shuffled, you can create your &lt;code&gt;MultiLoader&lt;/code&gt; instance and invoke its &lt;code&gt;addClip()&lt;/code&gt; method as before &amp;#8212; except, instead of specifying movie clip containers by name, you'll refer to them via their references as stored in the &lt;code&gt;containers&lt;/code&gt; array ... and because it's been shuffled (mixed randomly), you can reference your movie clip's in order, from zero to three (thus making four references):

&lt;pre&gt;&lt;code&gt;ml.addClip(&quot;image1.jpg&quot;, containers[0], {onLoadProgress:progressA, onLoadInit:initA});
ml.addClip(&quot;image2.jpg&quot;, containers[1], {onLoadProgress:progressB, onLoadInit:initB});
ml.addClip(&quot;image3.jpg&quot;, containers[2], {onLoadProgress:progressC, onLoadInit:initC});
ml.addClip(&quot;image4.jpg&quot;, containers[3], {onLoadProgress:progressD, onLoadInit:initD});&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Chuck,</p>
<p>Create an <code>Array</code> instance to store your references:</p>
<p><code>var containers:Array = new Array(clip1_mc, clip2_mc, clip3_mc, clip4_mc);</code></p>
<p>Now you have an array (a list, basically) that contains the instance names to your movie clips.  You can call the variable what you like, but I chose <code>containers</code> because that&#8217;s the role these movie clips play &mdash; they&#8217;re containers for your images.</p>
<p>Next, refer to the &#8220;Jump Randomly&#8221; article I linked to before to find the custom <code>shuffle()</code> function.  Use that function to re-arrange the elements of your <code>containers</code> array.  Now that they&#8217;ve been shuffled, you can create your <code>MultiLoader</code> instance and invoke its <code>addClip()</code> method as before &mdash; except, instead of specifying movie clip containers by name, you&#8217;ll refer to them via their references as stored in the <code>containers</code> array &#8230; and because it&#8217;s been shuffled (mixed randomly), you can reference your movie clip&#8217;s in order, from zero to three (thus making four references):</p>
<pre><code>ml.addClip("image1.jpg", containers[0], {onLoadProgress:progressA, onLoadInit:initA});
ml.addClip("image2.jpg", containers[1], {onLoadProgress:progressB, onLoadInit:initB});
ml.addClip("image3.jpg", containers[2], {onLoadProgress:progressC, onLoadInit:initC});
ml.addClip("image4.jpg", containers[3], {onLoadProgress:progressD, onLoadInit:initD});</code></pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Chuck</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-123764</link>
		<pubDate>Thu, 24 Jan 2008 20:15:43 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-123764</guid>
					<description>I am not sure how to go about it.</description>
		<content:encoded><![CDATA[<p>I am not sure how to go about it.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-117645</link>
		<pubDate>Sat, 05 Jan 2008 03:59:15 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-117645</guid>
					<description>&lt;strong&gt;To Mandy ...&lt;/strong&gt;

Thanks for your comments!  Something in my memory is telling me &amp;#8212; suggesting, more like &amp;#8212; that I replied to you personally via email, months ago.  If I didn't, then I apologize profusely for waiting so long to reply!  An &lt;code&gt;unloadClips()&lt;/code&gt; method sounds like a great idea.  Whenever I get around to updating this class (and there's no saying when that might be), I'll be happy to keep your suggestion in mind.

&lt;strong&gt;To Chuck ...&lt;/strong&gt;

The container clip is determined by the &lt;code&gt;addClip()&lt;/code&gt; method (it's the second parameter), so you could populate an array with references to your containers (&lt;code&gt;clip1_mc&lt;/code&gt;, &lt;code&gt;clip2_mc&lt;/code&gt;, etc.) and use the &lt;code&gt;shuffle()&lt;/code&gt; suggested in &quot;&lt;a href=&quot;http://www.quip.net/blog/2007/flash/how-to-jump-randomly-to-frame-labels-without-repeats&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;How to Jump Randomly to Frame Labels without Repeats&lt;/a&gt;&quot; to mix them up.  At that point, you could step through that array with a &lt;code&gt;for&lt;/code&gt; loop to invoke &lt;code&gt;addClip()&lt;/code&gt; &amp;#8212; or heck, you could even do it by hand:

&lt;pre&gt;&lt;code&gt;// assuming the array has already been shuffled ...
ml.addClip(&quot;file1.jpg&quot;, containers[0], {onLoadProgress:progressA, onLoadInit:initA});
ml.addClip(&quot;file2.jpg&quot;, containers[1], {onLoadProgress:progressB, onLoadInit:initB});
ml.addClip(&quot;file3.jpg&quot;, containers[2], {onLoadProgress:progressC, onLoadInit:initC});&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><strong>To Mandy &#8230;</strong></p>
<p>Thanks for your comments!  Something in my memory is telling me &mdash; suggesting, more like &mdash; that I replied to you personally via email, months ago.  If I didn&#8217;t, then I apologize profusely for waiting so long to reply!  An <code>unloadClips()</code> method sounds like a great idea.  Whenever I get around to updating this class (and there&#8217;s no saying when that might be), I&#8217;ll be happy to keep your suggestion in mind.</p>
<p><strong>To Chuck &#8230;</strong></p>
<p>The container clip is determined by the <code>addClip()</code> method (it&#8217;s the second parameter), so you could populate an array with references to your containers (<code>clip1_mc</code>, <code>clip2_mc</code>, etc.) and use the <code>shuffle()</code> suggested in &#8220;<a href="http://www.quip.net/blog/2007/flash/how-to-jump-randomly-to-frame-labels-without-repeats" target="_blank" rel="nofollow">How to Jump Randomly to Frame Labels without Repeats</a>&#8221; to mix them up.  At that point, you could step through that array with a <code>for</code> loop to invoke <code>addClip()</code> &mdash; or heck, you could even do it by hand:</p>
<pre><code>// assuming the array has already been shuffled ...
ml.addClip("file1.jpg", containers[0], {onLoadProgress:progressA, onLoadInit:initA});
ml.addClip("file2.jpg", containers[1], {onLoadProgress:progressB, onLoadInit:initB});
ml.addClip("file3.jpg", containers[2], {onLoadProgress:progressC, onLoadInit:initC});</code></pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Chuck</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-115453</link>
		<pubDate>Thu, 27 Dec 2007 16:48:18 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-115453</guid>
					<description>I have four images in the library (image1.jpg, image2.jpg, image3.jpg, image4.jpg).
I have four empty movie clips which I created the on the main timeline (clip1_mc, clip2_mc, clip3_mc, clip4_mc).

What I want to do is to ramdomly load and unload the images into the empty movie clips.
So, for example image1.jpg might load into clip2_mc and then unload, image4.jpg might load into clip1_mc etc.

Can you help?</description>
		<content:encoded><![CDATA[<p>I have four images in the library (image1.jpg, image2.jpg, image3.jpg, image4.jpg).<br />
I have four empty movie clips which I created the on the main timeline (clip1_mc, clip2_mc, clip3_mc, clip4_mc).</p>
<p>What I want to do is to ramdomly load and unload the images into the empty movie clips.<br />
So, for example image1.jpg might load into clip2_mc and then unload, image4.jpg might load into clip1_mc etc.</p>
<p>Can you help?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Mandy</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-81741</link>
		<pubDate>Sat, 15 Sep 2007 17:03:16 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-81741</guid>
					<description>Hi David, 

This is a really organized class. Thanks for it. Reminds me of all ajax libraries these days the way you wrote this class. I think you should consider writing your own library and releasing it as open source with all the cool classes that  you have written.

Finally, I think adding an public function unloadClips() would also be very useful when all clips need to be removed before loading the second set. Since this class tracks all the registered clips&amp;#38;handlers it should also be able to unload them.

Thoughts?

Thanks,
Mandy.</description>
		<content:encoded><![CDATA[<p>Hi David, </p>
<p>This is a really organized class. Thanks for it. Reminds me of all ajax libraries these days the way you wrote this class. I think you should consider writing your own library and releasing it as open source with all the cool classes that  you have written.</p>
<p>Finally, I think adding an public function unloadClips() would also be very useful when all clips need to be removed before loading the second set. Since this class tracks all the registered clips&amp;handlers it should also be able to unload them.</p>
<p>Thoughts?</p>
<p>Thanks,<br />
Mandy.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-67338</link>
		<pubDate>Thu, 26 Jul 2007 20:33:20 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part1#comment-67338</guid>
					<description>discorax,

I'm not sure I fully understand your question, to be honest, but that said ... have you read the follow up entry to this first one?  &lt;a href=&quot;http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2&quot; target=&quot;_blank&quot;&gt;Part 2&lt;/a&gt; features a private &lt;code&gt;getGroupProgress()&lt;/code&gt; method.</description>
		<content:encoded><![CDATA[<p>discorax,</p>
<p>I&#8217;m not sure I fully understand your question, to be honest, but that said &#8230; have you read the follow up entry to this first one?  <a href="http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2" target="_blank">Part 2</a> features a private <code>getGroupProgress()</code> method.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

