<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Create a pseudo-class from a runtime-loaded image in AS3</title>
	<atom:link href="http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/</link>
	<description>Josh Tynjala explores Flash, Flex, and ActionScript.</description>
	<lastBuildDate>Sat, 31 Jul 2010 02:55:11 -0400</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Metal Hurlant</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-24969</link>
		<dc:creator>Metal Hurlant</dc:creator>
		<pubDate>Wed, 21 Nov 2007 02:07:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-24969</guid>
		<description>Prototype isn&#039;t strictly needed here. A function created within a function is a closure, so it keeps a snapshot of the outer functions&#039; locale variables in its scope.

The body of createAutoLoader() can simply be:

&lt;pre&gt;&lt;code&gt;return function():Loader {
    var loader:Loader = new Loader();
    loader.load(new URLRequest(url), context);
    return loader;
};&lt;/code&gt;&lt;/pre&gt;

One behavioral difference between this and an embedded asset is the dreaded one-frame minimum wait for the remotely loaded image, even when the image is already in the browser cache.
There are workarounds for it. Ely Greenfield has a &lt;a href=&quot;http://www.quietlyscheming.com/blog/2007/01/29/new-flex-componentsample-superimage/&quot; rel=&quot;nofollow&quot;&gt;Flex SuperImage component&lt;/a&gt; that gets the general idea right.
To deal with multiple loads of the same asset, you&#039;d want to cache the BitmapData object, and associates that with the url. Further attempts to instanciate the AutoLoader would just create a new Bitmap with that BitmapData.</description>
		<content:encoded><![CDATA[<p>Prototype isn&#8217;t strictly needed here. A function created within a function is a closure, so it keeps a snapshot of the outer functions&#8217; locale variables in its scope.</p>
<p>The body of createAutoLoader() can simply be:</p>
<pre><code>return function():Loader {
    var loader:Loader = new Loader();
    loader.load(new URLRequest(url), context);
    return loader;
};</code></pre>
<p>One behavioral difference between this and an embedded asset is the dreaded one-frame minimum wait for the remotely loaded image, even when the image is already in the browser cache.<br />
There are workarounds for it. Ely Greenfield has a <a href="http://www.quietlyscheming.com/blog/2007/01/29/new-flex-componentsample-superimage/" rel="nofollow">Flex SuperImage component</a> that gets the general idea right.<br />
To deal with multiple loads of the same asset, you&#8217;d want to cache the BitmapData object, and associates that with the url. Further attempts to instanciate the AutoLoader would just create a new Bitmap with that BitmapData.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-22682</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Mon, 29 Oct 2007 19:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-22682</guid>
		<description>There&#039;s another solution, but it&#039;s really hacky.  You can create a stand-alone SWF that has your MyImageClass as a symbol in it (make sure to save the swf as uncompressed) and load it into your SWF as a bytearray.  Save a copy of this bytearray once it&#039;s loaded.

When you need to create a new class, make a copy of the bytearray and patch the data in the bytearray containing the string to the string you&#039;re interested in.  This clearly will require some hacking around with the SWF file format to make this work.  Finally, load from the bytearray and use getDefinition to get the class object.

This is clearly way overkill for the case at hand, though.  But it does illuminate thte possibility of generating classes at run-time.  It&#039;s just very, very difficult.

Too bad actionscript doesn&#039;t have eval().  :)</description>
		<content:encoded><![CDATA[<p>There&#8217;s another solution, but it&#8217;s really hacky.  You can create a stand-alone SWF that has your MyImageClass as a symbol in it (make sure to save the swf as uncompressed) and load it into your SWF as a bytearray.  Save a copy of this bytearray once it&#8217;s loaded.</p>
<p>When you need to create a new class, make a copy of the bytearray and patch the data in the bytearray containing the string to the string you&#8217;re interested in.  This clearly will require some hacking around with the SWF file format to make this work.  Finally, load from the bytearray and use getDefinition to get the class object.</p>
<p>This is clearly way overkill for the case at hand, though.  But it does illuminate thte possibility of generating classes at run-time.  It&#8217;s just very, very difficult.</p>
<p>Too bad actionscript doesn&#8217;t have eval().  <img src='http://joshblog.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-22094</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Mon, 22 Oct 2007 15:51:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-22094</guid>
		<description>Ian, I have not found a better solution.</description>
		<content:encoded><![CDATA[<p>Ian, I have not found a better solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Thomas</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-22087</link>
		<dc:creator>Ian Thomas</dc:creator>
		<pubDate>Mon, 22 Oct 2007 15:14:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-22087</guid>
		<description>Hi Josh,
  Sounds like I&#039;m currently jumping through exactly the same hoops as you; having real trouble generating a Class object uniquely tied to a BitmapAsset with some associated bitmap Data (I&#039;m trying to do something like you describe with the Flex .icon property). 

It&#039;s maddening. Did you get any further than you describe here?

Ian</description>
		<content:encoded><![CDATA[<p>Hi Josh,<br />
  Sounds like I&#8217;m currently jumping through exactly the same hoops as you; having real trouble generating a Class object uniquely tied to a BitmapAsset with some associated bitmap Data (I&#8217;m trying to do something like you describe with the Flex .icon property). </p>
<p>It&#8217;s maddening. Did you get any further than you describe here?</p>
<p>Ian</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-20686</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Thu, 04 Oct 2007 06:33:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-20686</guid>
		<description>TorbjÃ¸rn, I wouldn&#039;t be golden with your suggested method. What if I have two images to load? The static var only supports a single image unless I take special care in timing when the class may be used. I&#039;ll need to change the URL to load the second image, but what if the component needs to use the first URL again? It will have been lost.

Trust me, I tried &lt;em&gt;many&lt;/em&gt; possible approaches over a period of a few days, including what you&#039;ve suggested.</description>
		<content:encoded><![CDATA[<p>TorbjÃ¸rn, I wouldn&#8217;t be golden with your suggested method. What if I have two images to load? The static var only supports a single image unless I take special care in timing when the class may be used. I&#8217;ll need to change the URL to load the second image, but what if the component needs to use the first URL again? It will have been lost.</p>
<p>Trust me, I tried <em>many</em> possible approaches over a period of a few days, including what you&#8217;ve suggested.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-20645</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Wed, 03 Oct 2007 16:24:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-20645</guid>
		<description>I don&#039;t understand what you mean, maliboo. I had to use prototype to associate the URL with the anonymous function so that it could be passed to the new &lt;code&gt;Loader&lt;/code&gt;. Notice that I use &lt;code&gt;this.url&lt;/code&gt; in the function.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand what you mean, maliboo. I had to use prototype to associate the URL with the anonymous function so that it could be passed to the new <code>Loader</code>. Notice that I use <code>this.url</code> in the function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: maliboo</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-20562</link>
		<dc:creator>maliboo</dc:creator>
		<pubDate>Tue, 02 Oct 2007 17:44:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-20562</guid>
		<description>This function returns nothing but loader itself. So prototyping here is little bit useless;)

BTW: __proto__ was there since SWF5;)</description>
		<content:encoded><![CDATA[<p>This function returns nothing but loader itself. So prototyping here is little bit useless;)</p>
<p>BTW: __proto__ was there since SWF5;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TorbjÃ¸rn Caspersen</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-20473</link>
		<dc:creator>TorbjÃ¸rn Caspersen</dc:creator>
		<pubDate>Mon, 01 Oct 2007 11:53:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-20473</guid>
		<description>Why not use a static public var or static getter/setter in your class to set the URL? Extend the images class, add static functions, override loader functions and you should be golden. 

I&#039;ve used this technique before, great way to keep classes from knowing about each other.

Feel free to contact me if anything is unclear.</description>
		<content:encoded><![CDATA[<p>Why not use a static public var or static getter/setter in your class to set the URL? Extend the images class, add static functions, override loader functions and you should be golden. </p>
<p>I&#8217;ve used this technique before, great way to keep classes from knowing about each other.</p>
<p>Feel free to contact me if anything is unclear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Campbell</title>
		<link>http://joshblog.net/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/comment-page-1/#comment-20357</link>
		<dc:creator>Campbell</dc:creator>
		<pubDate>Sat, 29 Sep 2007 11:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/09/28/actionscript-3-bitmap-image-classes-with-functions-and-loaders/#comment-20357</guid>
		<description>Ahhh yes the restrictions of a strongly typed language. You cant create new classes at runtime and you cant delete instance variables etc etc. Sometimes it was nice to have these options to create some really magick things. I have started using the proxy methods a lot to try and get object to be a bit more dynamic.</description>
		<content:encoded><![CDATA[<p>Ahhh yes the restrictions of a strongly typed language. You cant create new classes at runtime and you cant delete instance variables etc etc. Sometimes it was nice to have these options to create some really magick things. I have started using the proxy methods a lot to try and get object to be a bit more dynamic.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
