<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Touch My Pixel Blog &#187; JSFL</title>
	<atom:link href="http://blog.touchmypixel.com/tag/jsfl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.touchmypixel.com</link>
	<description>Games + Web : Interaction Matters</description>
	<lastBuildDate>Thu, 22 Jul 2010 04:18:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JSFL: Select all classes of the selected type on layer</title>
		<link>http://blog.touchmypixel.com/2008/04/jsfl-select-all-classes-of-the-selected-type-on-layer/</link>
		<comments>http://blog.touchmypixel.com/2008/04/jsfl-select-all-classes-of-the-selected-type-on-layer/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 06:15:12 +0000</pubDate>
		<dc:creator>tarwin</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://blog.touchmypixel.com/?p=3</guid>
		<description><![CDATA[I've been playing with JSFL a little recently. It was really hard to begin finding any resources on how to use it and those I did find were pretty sparse with information. So to help the community out I'm going to start posting my experiments, some useful, some only good for me, for everyone to [...]]]></description>
			<content:encoded><![CDATA[<p>I've been playing with JSFL a little recently. It was really hard to begin finding any resources on how to use it and those I did find were pretty sparse with information. So to help the community out I'm going to start posting my experiments, some useful, some only good for me, for everyone to take a look at, take apart and generally learn from.</p>
<p>The first one is one of the simplest. It lets you select all <em>Elements</em> of the same class on the stage. Simply select one of them, say a <em>RadioButton, </em>then choose the <em>TMP - Select Same Class</em> from the <em>Commands</em> menu and all other <em>RadioButton</em> instances should be selected.</p>
<p><span id="more-3"></span><br />
I've been using this in a game I've been creating. I just lazily drag a bunch of different enemies onto one layer, then when I want to seperate them onto different layers just use this command. Easy. So here it is.</p>
<pre>
<div class="igBar"><span id="ljavascript-2"><a href="#" onclick="javascript:showPlainTxt('javascript-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-2">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">doc = fl.<span style="color: #006600;">getDocumentDOM</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">s = doc.<span style="color: #006600;">selection</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>s.<span style="color: #006600;">length</span> == <span style="color: #CC0000;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; type = s<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">libraryItem</span>.<span style="color: #006600;">linkageBaseClass</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> tl = doc.<span style="color: #006600;">getTimeline</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> elts = tl.<span style="color: #006600;">layers</span><span style="color: #66cc66;">&#91;</span>tl.<span style="color: #006600;">currentLayer</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">frames</span><span style="color: #66cc66;">&#91;</span>tl.<span style="color: #006600;">currentFrame</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">elements</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; a = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span>i=<span style="color: #CC0000;color:#800000;">0</span>; i &lt;elts.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>elts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">libraryItem</span>.<span style="color: #006600;">linkageBaseClass</span> == type<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>elts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; doc.<span style="color: #006600;">selection</span> = a;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>

</pre>
<p>Yeah, stupid directory I know. I'll show you how to make an MXP installer in a later post, to make it easier to send these things around.</p>
<p>The "fl." holds all the functions that a Flash specific in JSFL. The rest of the code is just plain old Javascript, so if you need help with that just do a search on the net for general Javascript documentation.</p>
<p>Firstly we create a variable <em>doc </em>to make it easier to access our current document. Then <em>s</em> which holds an array of all the <em>Element</em><em>s</em><em> </em>currently selected. We check to make sure that we've only selected one <em>Element</em> (we could at this stage do an fl.alert("message") to warn that there was more than one item selected. If there is only one item selected we get the type using the <em>.libraryItem.linkageBaseClass</em> and then set another variable <em>tl</em> to make it quick to access the current timeline.</p>
<p>The next bit is a bit complicated. I get all the elements on the current layer, in the current timeline and put them into the array <em>elts</em>. If someone wants to update this I'd suggest the first place to start would be to get it to select elements on ALL layers. Would be useful.</p>
<p>I then loop through the array of <em>Elements</em> and add them to a temporary array <em>a,</em> but only if their <em>linkageBaseClass</em> ist the same as the initially selected one (it's just a simple String).</p>
<p>Lastly, set the document selection to the temporary array of <em>Elements</em>.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.71';
var flattr_uid = 'tarwin';
var flattr_cat = 'text';
var flattr_tle = 'JSFL: Select all classes of the selected type on layer';
var flattr_dsc = 'I\'ve been playing with JSFL a little recently. It was really hard to begin finding any resources on how to use it and those I did find were pretty sparse with information. So to help the community out I\'m going to start posting my experiments, some useful, some only good for me, for everyone to take a look at, take apart and generally learn from.  The first one is one of the simplest. It lets you select all Elements of the same class on the stage. Simply select one of them, say a RadioButton, then choose the TMP - Select Same Class from the Commands menu and all other RadioButton instances should be selected.   I\'ve been using this in a game I\'ve been creating. I just lazily drag a bunch of different enemies onto one layer, then when I want to seperate them onto different layers just use this command. Easy. So here it is.  [js] doc = fl.getDocumentDOM(); s = doc.selection; if(s.length == 1){ 	type = s[0].libraryItem.linkageBaseClass;  	var tl = doc.getTimeline() 	var elts = tl.l';
var flattr_tag = 'Flash,JSFL';
var flattr_url = 'http://blog.touchmypixel.com/2008/04/jsfl-select-all-classes-of-the-selected-type-on-layer/';
var flattr_lng = 'en_GB';
</script><script src="http://api.flattr.com/button/load.js" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this!"></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.touchmypixel.com/2008/04/jsfl-select-all-classes-of-the-selected-type-on-layer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
