<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>FlashBannerOnline</title>
	
	<link>http://blog.flashbanneronline.com</link>
	<description>Online Flash Banner Generator blog!</description>
	<lastBuildDate>Thu, 29 Oct 2009 04:35:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/flashbanneronlineblog" type="application/rss+xml" /><feedburner:emailServiceId>flashbanneronlineblog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Passing Arguments with Events in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/tFHxcoxWSss/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/passing-arguments-with-events-in-as3/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 04:35:12 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[Arguments]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Clone]]></category>
		<category><![CDATA[const]]></category>
		<category><![CDATA[dispatchEvent]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[formatToString]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[Passing]]></category>
		<category><![CDATA[super]]></category>
		<category><![CDATA[toString]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=273</guid>
		<description><![CDATA[





One of the questions about ActionScript 3 that I am most often asked is how to send arguments to a listener function along with an event.
To provide some background for this question, you could send argument data to a standard function like this?
function showMsg(msg:String):void {
    trace(msg);
}
showMsg("Claire");
However, in an event listener, only one [...]]]></description>
			<content:encoded><![CDATA[<p>One of the questions about ActionScript 3 that I am most often asked is how to send arguments to a listener function along with an event.</p>
<p>To provide some background for this question, you could send argument data to a standard function like this?</p>
<pre>function showMsg(msg:String):void {
    trace(msg);
}
showMsg("Claire");</pre>
<p>However, in an event listener, only one argument is allowed in the listener function: the argument responsible for receiving the event data. Using a standard mouse click listener as an example&#8230;</p>
<pre>stage.addEventListener(MouseEvent.CLICK, showMsg, false, 0, true);
function showMsg(evt:MouseEvent):void {
    trace("hello");
}</pre>
<p>&#8230;the kind of question asked is, can you do something like this:</p>
<pre>stage.addEventListener(MouseEvent.CLICK, showMsg, "hello",
                       false, 0, true);
function showMsg(evt:MouseEvent, msg:String):void {
    trace(msg);
}</pre>
<p>The answer is, not out of the box. The existing AS3 events do not provide for this capability. However, to answer Jim&#8217;s question, the best way to pass arguments with an event is to create your own event class by extending AS3&#8217;s <span>Event</span> class.</p>
<p><span id="more-56"> </span></p>
<h2>No-Class Alternatives</h2>
<p>Before we get to the custom class, let&#8217;s look at a few lesser approaches for using dynamic data with events. In the following examples, I&#8217;ll take advantage of properties from an event, along with dynamic data, to show the use of both kinds of information. A <span>MouseEvent</span> instance includes a Boolean called <span>shiftKey</span> that indicates whether or not the shift key is pressed at the time the event is dispatched.</p>
<p><em>Note: Any time a <span>trace()</span> method is used to trace an empty string or new line, it is only used to visually differentiate one trace from another in the Output panel.</em></p>
<p>The first approach is to populate a variable and then use that variable inside the listener function. This is straightforward, but not very dynamic:</p>
<pre>var msg:String = "Shift key was down:";

stage.addEventListener(MouseEvent.CLICK, doIt, false, 0, true);
function doIt(evt:MouseEvent) {
    trace(msg, evt.shiftKey);
    trace("");
    trace(evt);
}</pre>
<p>The second approach is to use a standard event to call an interim function that then calls the desired function, passing along any relevant information. In my opinion, this is the best out-of-the-box solution, but it is also more verbose:</p>
<pre>stage.addEventListener(MouseEvent.CLICK, doIt, false, 0, true);
function doIt(evt:MouseEvent) {
    doIt2("Shift key was down:", evt);
}

function doIt2(msg:String, evt:*) {
    trace(msg, evt.shiftKey);
    trace("");
    trace(evt);
}</pre>
<p>The last approach I&#8217;ll discuss in this post is to use an anonymous function within the <span>addEventListener()</span> method under the guise of elminating the interim function in the previous example. This is a bit ugly and problematic:</p>
<pre>stage.addEventListener(MouseEvent.CLICK,
              function(evt:MouseEvent){doIt(evt, "Shift key was down:")},
              false, 0, true);

function doIt(evt:MouseEvent, msg:String) {
    trace(msg, evt.shiftKey);
    trace("");
    trace(evt);
}</pre>
<p>Looking at this format objectively, it&#8217;s not really any less verbose, it&#8217;s just crammed into one line. It&#8217;s also harder to read—particularly when the anonymous function requires more than one line to execute the desired functionality. Most importantly, however, anonymous functions can be a pain to work with and are hard (impossible?) to clean up after. With AS3&#8217;s memory management requirements, this is a headache you just don&#8217;t need.</p>
<h2>Creating a Custom Event Class</h2>
<p>For our needs, we&#8217;ll create a custom event class by extending <span>Event</span>. This gives us all the advantages of the parent class, including dispatching. Here is a basic example that I&#8217;ll explain bit by bit:</p>
<div>
<div id="actionscript3-1">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">package</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> <span style="color: #0033ff;">flash.events</span>.<span style="color: #0033ff;">Event</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">class</span> CustomEvent <span style="color: #0033ff;">extends</span> <span style="color: #0033ff;">Event</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">static</span> <span style="color: #0033ff;">const</span> CUSTOM:<span style="color: #0033ff;">String</span> = <span style="color: #00aa00;">&#8220;custom&#8221;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">var</span> arg:<span style="color: #0033ff;">*</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">function</span> CustomEvent<span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>:<span style="color: #0033ff;">String</span>, customArg:<span style="color: #0033ff;">*</span>=<span style="color: #0033ff;">null</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">bubbles</span>:<span style="color: #0033ff;">Boolean</span>=<span style="color: #0033ff;">false</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">cancelable</span>:<span style="color: #0033ff;">Boolean</span>=<span style="color: #0033ff;">false</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">super</span><span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>, <span style="color: #0033ff;">bubbles</span>, <span style="color: #0033ff;">cancelable</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.arg = customArg;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">override</span> <span style="color: #0033ff;">function</span> <span style="color: #0033ff;">clone</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">Event</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">return</span> <span style="color: #0033ff;">new</span> CustomEvent<span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>, arg, <span style="color: #0033ff;">bubbles</span>, <span style="color: #0033ff;">cancelable</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">override</span> <span style="color: #0033ff;">function</span> <span style="color: #0033ff;">toString</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">String</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">return</span> <span style="color: #0033ff;">formatToString</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;CustomEvent&#8221;</span>, <span style="color: #00aa00;">&#8220;type&#8221;</span>, <span style="color: #00aa00;">&#8220;arg&#8221;</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #00aa00;">&#8220;bubbles&#8221;</span>, <span style="color: #00aa00;">&#8220;cancelable&#8221;</span>, <span style="color: #00aa00;">&#8220;eventPhase&#8221;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>The class begins with the package declaration, and an import statement to tell the compiler where to find the <span>Event</span> class. The class declaration follows, extending <span>Event</span>.</p>
<p>The next line declares a public static constant, <span>CUSTOM</span>. This is the constant that will allow a scripter to specify this event, the same way you use <span>CLICK</span> to declare a click event of the <span>MouseEvent</span> class. These constants are strings and it&#8217;s best to specify something that will not conflict with another event string assignment (and, therefore, possibly trigger another event listener).</p>
<p>Next is a public property for any data you want to send with the event, such as the aforementioned <span>shiftKey</span> property found in the <span>MouseEvent</span> class. In this simple case, the value is typed using the asterisk, which will prevent type checking allowing any data type to be used.</p>
<p><em>It is largely a matter of preference whether you prefer to use public variables or getters and setters for accessing properties from outside a class. Many OOP advocates will insist that getters and setters are the only way to go. Others maintain that &#8220;headless/brainless&#8221; getters and setters (functions that don&#8217;t add any functionality, such as error checking, casting, or other manipulation) offer little value.</p>
<p>I leave it to you to decide. In the downloadable source files, I&#8217;ve provided two versions of the next custom event class discussed in this post (&#8217;a practical example&#8217;) with which you can experiment. You need only swap the classes and everything will work the same way, regardless of which approach you prefer.</p>
<p>If this doesn&#8217;t mean anything to you, just stick with the version used in the examples (that uses public properties) until you learn more about getters and setters and determine your own personal preference on the issue. You can start looking into the idea with Chapter 6 of the book (OOP), which briefly demonstrates getters and setters in the Encapsulation and Composition sections.</em></p>
<p>The class constructor begins on line 11 and is very simple. It accepts as parameters, the event type, the custom argument, and the ability to bubble or cancel the event (the latter two, false by default). Only the custom argument is different from a standard event. It is placed second in the list of parameters so you can omit the last few parameters from the event dispatch. Their default values will be used if they are omitted. Similarly, if no new custom data is provided, it&#8217;s default value of <span>null</span> will be used. If the custom argument was placed at the end of the list (a logical place for new information), you would have to include values for all the optional parameters in the correct order, just to change the custom data argument.</p>
<p>The next line calls the super class to reap all of its benefits, passing along the type, bubbles and cancelable setting. Note that the argument is not passed on here because it&#8217;s not a feature of the extended <span>Event</span></p>
<h3>Additional Features</h3>
<p>Theoretically, you can stop here but there are two important features that you should also include to make your class feature-complete.</p>
<h4>clone()</h4>
<p>On Line 21, our custom class overrides the <span>clone()</span> method of the parent class. This is necessary to insure that your event will behave properly if you ever need to redispatch it. The clone() method is called automatically for a built-in class but, when extending a class, you must account for the new features of your class and override the original method. Without including this override, none of the event attributes will carry through and you will receive an error. The source code that accompanies this post includes an example of redispatching the event. You can try the file with and without the function override to see how this might impact your project.</p>
<h4>toString()</h4>
<p>Finally, an &#8220;undersung&#8221; hero of the Event class appears on line 25. If you override the <span>toString()</span> method as well, including your class name, custom argument, and original event attributes (<span>type</span>, <span>bubbles</span>,  and <span>cancelable</span>), your custom class info will appear in any trace of the event. This is handy for quick references to property names. For example, if you don&#8217;t override the method, and trace the event with a custom argument like this:</p>
<p><span style="margin-left: 40px;"><span>trace(new CustomEvent(CustomEvent.CUSTOM, &#8220;Claire&#8221;));</span></span></p>
<p>&#8230;you&#8217;ll get the following:</p>
<p><span style="margin-left: 40px;"><span>[Event type="custom" bubbles=false cancelable=false eventPhase=2]</span></span></p>
<p>All you know is that an <span>Event</span> of type &#8220;custom&#8221; was dispatched. However, if you override the method as shown, you get this:</p>
<p><span style="margin-left: 40px; display: block;"><span>[CustomEvent type="custom" arg="Claire" bubbles=false cancelable=false<br />
eventPhase=2]</span></span></p>
<p>Not only do you know that you&#8217;re working with a <span>CustomEvent</span>, you also see the custom value you&#8217;ve added (arg=&#8221;Claire&#8221;).</p>
<h3>Using the Custom Event</h3>
<p>You can use the custom event like this, which will trace both the event and the custom argument that you send with the event:</p>
<pre>this.addEventListener(CustomEvent.CUSTOM, onCustom, false, 0, true);
function onCustom(evt:CustomEvent):void {
    trace(evt);
    trace(evt.arg);
}

dispatchEvent(new CustomEvent(CustomEvent.CUSTOM, "Claire"));</pre>
<h2>A Practical Example</h2>
<p>Now let&#8217;s look at a custom class at work. The following application is a very basic simulation of registering a user for something. We&#8217;ll be using a custom event class, <span>UserRegistrationEvent</span>. The interface requires a user name and age, and an optional employment status can also be provided. Upon an attempt to register, basic error-checking is performed. If the name field is empty, or the age provided is less than 18, a custom error event <span>USER_REGISTRATION_ERROR</span>, is dispatched, and a warning string is placed into the Result field. Otherwise, a custom complete event, <span>USER_REGISTRATION_COMPLETE</span>, is dispatched and each of the custom values carried with the event is placed into the field. For demo purposes, the full event is added to the field in each case.</p>
<div id="swf23ce_1" style="text-align: center;"><object id="id1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="469" height="341" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="name" value="id1" /><param name="src" value="http://www.learningactionscript3.com/wp-content/uploads/blog_no_redispatch.swf" /><param name="wmode" value="window" /><param name="allowfullscreen" value="true" /><param name="quality" value="high" /><embed id="id1" type="application/x-shockwave-flash" width="469" height="341" src="http://www.learningactionscript3.com/wp-content/uploads/blog_no_redispatch.swf" quality="high" allowfullscreen="true" wmode="window" name="id1"></embed></object></div>
<p><script type="text/javascript">// <![CDATA[
var vswf = new SWFObject("/wp-content/uploads/blog_no_redispatch.swf", "id1", "550", "400", "9", "#FF0000");
vswf.addParam("wmode", "window");
vswf.addParam("menu", "true");
vswf.addParam("quality", "high");
vswf.addParam("allowFullScreen", "true");
vswf.write("swf23ce_1");
// ]]&gt;</script></p>
<p>Here is the custom event class used. The only significant differences between this example and the earlier custom event class are the fact that <span>UserRegistrationEvent</span> has two event constants (instead of one), and three custom values (instead of one).</p>
<div>
<div id="actionscript3-2">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">package</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> <span style="color: #0033ff;">flash.events</span>.<span style="color: #0033ff;">Event</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">class</span> UserRegistrationEvent <span style="color: #0033ff;">extends</span> <span style="color: #0033ff;">Event</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">static</span> <span style="color: #0033ff;">const</span> USER_REGISTRATION_COMPLETE:<span style="color: #0033ff;">String</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">= <span style="color: #00aa00;">&#8220;userRegistrationComplete&#8221;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">static</span> <span style="color: #0033ff;">const</span> USER_REGISTRATION_ERROR:<span style="color: #0033ff;">String</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">= <span style="color: #00aa00;">&#8220;userRegistrationError&#8221;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">var</span> <span style="color: #0033ff;">name</span>:<span style="color: #0033ff;">String</span> = <span style="color: #00aa00;">&#8220;&#8221;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">var</span> age:<span style="color: #0033ff;">int</span> = <span style="color: #000000;">0</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">var</span> employed:<span style="color: #0033ff;">Boolean</span> = <span style="color: #0033ff;">false</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">function</span> UserRegistrationEvent<span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>:<span style="color: #0033ff;">String</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">name</span>:<span style="color: #0033ff;">String</span>=<span style="color: #00aa00;">&#8220;&#8221;</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">age:<span style="color: #0033ff;">int</span>=<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">employed:<span style="color: #0033ff;">Boolean</span>=<span style="color: #0033ff;">false</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">bubbles</span>:<span style="color: #0033ff;">Boolean</span>=<span style="color: #0033ff;">false</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">cancelable</span>:<span style="color: #0033ff;">Boolean</span>=<span style="color: #0033ff;">false</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">super</span><span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>, <span style="color: #0033ff;">bubbles</span>, <span style="color: #0033ff;">cancelable</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.<span style="color: #0033ff;">name</span> = <span style="color: #0033ff;">name</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.age = age;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.employed = employed;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">override</span> <span style="color: #0033ff;">function</span> <span style="color: #0033ff;">clone</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">Event</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">return</span> <span style="color: #0033ff;">new</span> UserRegistrationEvent<span style="color: #000000;">(</span><span style="color: #0033ff;">type</span>, <span style="color: #0033ff;">name</span>, age, employed,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">bubbles</span>, <span style="color: #0033ff;">cancelable</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">public</span> <span style="color: #0033ff;">override</span> <span style="color: #0033ff;">function</span> <span style="color: #0033ff;">toString</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">String</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">return</span> <span style="color: #0033ff;">formatToString</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;UserRegistrationEvent&#8221;</span>, <span style="color: #00aa00;">&#8220;type&#8221;</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #00aa00;">&#8220;name&#8221;</span>, <span style="color: #00aa00;">&#8220;age&#8221;</span>, <span style="color: #00aa00;">&#8220;employed&#8221;</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #00aa00;">&#8220;bubbles&#8221;</span>, <span style="color: #00aa00;">&#8220;cancelable&#8221;</span>, <span style="color: #00aa00;">&#8220;eventPhase&#8221;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>And here is the relevant code that checks the form input and dispatches the appropriate event (with explanations to follow the script):</p>
<p><span><br />
</span></p>
<div>
<div id="actionscript3-3">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">//form button listener</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regBtn.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #0033ff;">MouseEvent</span>.<span style="color: #0033ff;">CLICK</span>, onReg, <span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onReg<span style="color: #000000;">(</span>evt:<span style="color: #0033ff;">MouseEvent</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">var</span> userAgeInt:<span style="color: #0033ff;">int</span> = <span style="color: #0033ff;">int</span><span style="color: #000000;">(</span>userAge.<span style="color: #0033ff;">text</span><span style="color: #000000;">)</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">if</span> <span style="color: #000000;">(</span>userName.<span style="color: #0033ff;">text</span> != <span style="color: #00aa00;">&#8220;&#8221;</span> &amp;&amp; userAgeInt&gt; <span style="color: #000000;">18</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">dispatchEvent</span><span style="color: #000000;">(</span><span style="color: #0033ff;">new</span> UserRegistrationEvent<span style="color: #000000;">(</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">UserRegistrationEvent.USER_REGISTRATION_COMPLETE,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">userName.<span style="color: #0033ff;">text</span>, userAgeInt, userEmployed.check.<span style="color: #0033ff;">visible</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span> <span style="color: #0033ff;">else</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">dispatchEvent</span><span style="color: #000000;">(</span><span style="color: #0033ff;">new</span> UserRegistrationEvent<span style="color: #000000;">(</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">UserRegistrationEvent.USER_REGISTRATION_ERROR<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">//reg complete listener</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span>UserRegistrationEvent.USER_REGISTRATION_COMPLETE,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">onRegComplete, <span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onRegComplete<span style="color: #000000;">(</span>evt:UserRegistrationEvent<span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">text</span> = evt.<span style="color: #0033ff;">name</span> + <span style="color: #00aa00;">&#8220;<span>\n</span>&#8220;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #0033ff;">String</span><span style="color: #000000;">(</span>evt.age<span style="color: #000000;">)</span> + <span style="color: #00aa00;">&#8220;<span>\n</span>&#8220;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #0033ff;">String</span><span style="color: #000000;">(</span>evt.employed<span style="color: #000000;">)</span><span style="color: #000000;">)</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;<span>\n</span><span>\n</span>&#8220;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #0033ff;">String</span><span style="color: #000000;">(</span>evt<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">//reg error listener</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">this</span>.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span>UserRegistrationEvent.USER_REGISTRATION_ERROR,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">onRegError, <span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onRegError<span style="color: #000000;">(</span>evt:UserRegistrationEvent<span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">text</span> = <span style="color: #00aa00;">&#8220;Error during registration. </span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #00aa00;"> Please check form input and try again.&#8221;</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;<span>\n</span><span>\n</span>&#8220;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">regResult.<span style="color: #0033ff;">appendText</span><span style="color: #000000;">(</span><span style="color: #0033ff;">String</span><span style="color: #000000;">(</span>evt<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>Lines 2 through 13 make up the listener for the Registration button in the form. The function converts the age text submission to an integer and checks to see if the age is over 18 and the name field is not empty. If these two tests pass, a registration complete event is dispatched, sending the name, age, and employment status with the event. If the tests fail, a registration error event is dispatched.</p>
<p>Lines 16 through 25 comprise the listener for the registration complete event. It places four pieces of information into the text field: the user&#8217;s name, age, and employment status, followed by the entire event for illustration purposes. (Line feeds are added along the way for clarity.)</p>
<p>Lines 28 through 36 contain the listener for the registration error event. It replaces the contents of the Result field with an error message and the complete event.</p>
<p><em>Note: The source code places the data in the text field but traces the event to the Output panel for additional separation of functionality. It also includes additional code to control the checkbox, which is irrelevant to this tutorial.</em></p>
<h2>Example Source Code</h2>
<p><img style="vertical-align: middle;" title="Download: Passing Arguments with Events" src="http://learningactionscript3.com/wp-content/plugins/downloadmanager/images/drive_go.gif" alt="Download: Passing Arguments with Events" /> <strong><a title="Download: Passing Arguments with Events" href="http://www.learningactionscript3.com/download/36/">Download Passing Arguments with Events</a></strong> (40.8 KB, 780 hits)</p>
<p>The source code that accompanies this post contains several files. Flash users should start with a set of FLA files (saved in CS3 format for maximum compatibility), including the example shown herein. In this set are a simple proof of concept, the basic UI example above, and a UI example that shows the importance of using the <span>clone()</span> method when redispatching events.</p>
<p>I&#8217;ve also included a set of class-only files, moving the FLA-based material to a class so users of other coding environments can take advantage of the examples. Furthermore, the classes can be used as document classes by Flash users, if preferred. Both the single dispatch and redispatch examples are included.</p>
<p>Finally, two versions of the custom event have been included, as explained earlier in the post. The version used with the example uses public properties for simplicity, but another version using getters and setters has also been provided. If you are a fan of the latter, you can simply swap out the class and everything will work the same way.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=tFHxcoxWSss:5wgb7GoeUNU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=tFHxcoxWSss:5wgb7GoeUNU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=tFHxcoxWSss:5wgb7GoeUNU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=tFHxcoxWSss:5wgb7GoeUNU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=tFHxcoxWSss:5wgb7GoeUNU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=tFHxcoxWSss:5wgb7GoeUNU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=tFHxcoxWSss:5wgb7GoeUNU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=tFHxcoxWSss:5wgb7GoeUNU:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/tFHxcoxWSss" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/passing-arguments-with-events-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/passing-arguments-with-events-in-as3/</feedburner:origLink></item>
		<item>
		<title>TweenLite Introduction AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/ptn8X2ek9cA/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/tweenlite-introduction-as3/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 04:10:46 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[TweenLite]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=270</guid>
		<description><![CDATA[Motion Myth
For some reason lots of people seem to think that ActionScript animation creates smoother animation than the Flash timeline. This is simply not true. The timeline is just as capable of creating &#8220;smooth&#8221; animations as ActionScript is.
On the timeline, if you want a smoother animation, use a framerate around 30fps and put more space [...]]]></description>
			<content:encoded><![CDATA[<h3>Motion Myth</h3>
<p>For some reason lots of people seem to think that ActionScript animation creates smoother animation than the Flash timeline. This is simply not true. The timeline is just as capable of creating &#8220;smooth&#8221; animations as ActionScript is.</p>
<p><em>On the timeline, if you want a smoother animation, use a framerate around 30fps and put more space between your keyframes.</em></p>
<h3>ActionScript vs. Timeline</h3>
<p>Students sometimes ask me when to use coded animation and when to use timeline animation. The answer is more complicated than you might expect. Here&#8217;s a basic set of rules:</p>
<p><strong>TIMELINE ANIMATION IS FOR:</strong><br />
- animation that is always the same (static animation)</p>
<p><strong>ACTIONSCRIPT ANIMATION IS FOR:</strong><br />
- interactive animation<br />
- random animation<br />
- animation driven from an outside source like an rss feed<br />
- complex, static physics simulations that would be hard to animate on the timeline<br />
- complex interactive physics simulation<br />
- time-based animation—that is, animation that always runs at the same speed independent of framerate</p>
<p><span id="more-50"> </span></p>
<p>When I first started using Flash, I programmed all my animation and avoided the timeline completely. This approach had an upside and a downside. The upside was that I learned a whole lot about making things move on the screen with code. The downside was that coding static animation is generally more time consuming then doing it on the timeline. Since coding static animations can be a good learning experience, I always tell my students to abide by the above list, but that the real choice of using ActionScript or timeline animation is up to them.</p>
<h3>First Encounter With TweenLite</h3>
<p>Until recently I had steered clear of all tweening engines for no reason in particular other than that I understood all the inner workings of them and would usually just write out motion math from memory when needed. A few months ago I was working as a consultant on a project with a few designers and a programmer. I knew that the designers liked to use tweening engines like Fuse, Tweener and TweenLite. I figured since they were using them, I should become familiar with them. I had also recently seen a <a href="http://drawlogic.com/2008/01/25/as3-animation-base-library-go-performance-tests/" target="_blank">graph</a> about the speed of different tweening engines and made a note to myself to check out TweenLite. After a 5-minute explanation from a designer, I was up and running with TweenLite. I thought it was cool, but didn&#8217;t think I&#8217;d find myself using it regularly.</p>
<p>When I got home that night I felt like playing with it a little more and I created <a href="http://www.learningactionscript3.com/wp-content/uploads/tweenLitePlay.html" target="_blank">this</a>.</p>
<p><img style="vertical-align: middle;" title="Download: TweenLite Play" src="http://learningactionscript3.com/wp-content/plugins/downloadmanager/images/drive_go.gif" alt="Download: TweenLite Play" /> <strong><a title="Download: TweenLite Play" href="http://www.learningactionscript3.com/download/31/">Download TweenLite Play</a></strong> (12.8 KB, 1,965 hits)</p>
<p><em>The source for this is a bit advanced, I recommend reading through this post before playing with this file.</em></p>
<p>I had a class the following day and I decided to add a short TweenLite demo into the lesson plan. It was about this point that I started to realize the potential power of TweenLite. The library is so elegantly designed that my students picked it up almost immediately.</p>
<h3>What is Time Based Animation?</h3>
<p>TweenLite creates time-based animation. This means that if you tell a tween to last 2 seconds. It will always last 2 seconds no matter what framerate the SWF happens to be playing at. When a SWF runs on a slow computer it might not be able to run at the framerate you intended. If your SWF has timeline animation, the animation will look like its playing in slow motion. If your animation is time-based (like TweenLite), it will appear more choppy, but will still run at the same speed:</p>
<div id="swf948f_1" style="text-align: center;"><embed id="id1" type="application/x-shockwave-flash" width="290" height="300" src="http://www.learningactionscript3.com/wp-content/uploads/animation_types.swf" name="id1" quality="high" wmode="window" menu="true" allowfullscreen="true"></embed></div>
<p><script type="text/javascript">// <![CDATA[
var vswf = new SWFObject("/wp-content/uploads/animation_types.swf", "id1", "290", "300", "9", "#FF0000");
vswf.addParam("wmode", "window");
vswf.addParam("menu", "true");
vswf.addParam("quality", "high");
vswf.addParam("allowFullScreen", "true");
vswf.write("swf948f_1");
// ]]&gt;</script><br />
<em>Move the fps slider to see the difference between a TweenLite frame-based tween and a normal Flash timeline tween. Note that the frame-based tween continues to take approximately 2 seconds to complete at any framerate. Whereas the Flash timeline tween is entirely dependent on the framerate of the SWF.</em></p>
<h3>Getting Started</h3>
<p>The first thing you need to do to start working with TweenLite is to <a href="http://blog.greensock.com/tweenliteas3/">download it</a>. Extract the zip and grab the &#8220;gs&#8221; folder. You can put it in your classpath or you can just place it next to your FLA. Once you&#8217;ve done either of those two things you&#8217;ll be ready to go.</p>
<p>In order to use TweenLite we need to import it. TweenLite uses the same static easing functions that Flash&#8217;s internal tweening engine uses, so when using TweenLite we generally have two import statements:</p>
<pre>import gs.TweenLite;
import fl.motion.easing.*;</pre>
<p>Add that code to your timeline, draw a box on your stage and convert it to a movie clip. Give it an instance name of <span>box</span> and add one more line of code to your timeline:</p>
<pre>TweenLite.to(box,2,{x:400});</pre>
<p>Make sure your box is somewhere on the left hand side of the stage and then test your movie. If you&#8217;ve done everything correctly, your box should move to 400 on the x axis. The <span>TweenLite.to()</span> method is really handy and very easy to understand. It takes three arguments. The first is the display object to tween. The second is how long the tween should take, and the third is an object that tells TweenLite which properties to tween.</p>
<p>Let&#8217;s change our call to <span>TweenLite.to()</span> a little bit:</p>
<pre>TweenLite.to(box,3 ,{x:400, rotation:180, scaleX:2, scaleY:2});</pre>
<p>This time, we tell our tween to last three seconds and we start playing with more than one property at a time. We move to 400 on the x, rotate to 180 and scale the movie clip up to 200%. Test your movie and have a look.</p>
<p>By default TweenLite uses a quadratic ease out equation. All the different types of tweens we can use are defined in the <a href="http://livedocs.adobe.com/Flash/9.0/ActionScriptLangRefV3/fl/motion/easing/package-detail.html"><span>fl.motion.easing</span></a> package:</p>
<p>The third argument of the <span>TweenLite.to()</span> method has a few special properties that give us more control over the tween. The first one is <span>ease</span>, this is where we use the functions from the <span>fl.motion.easing</span> package. Try a couple different values to get a feel for the different types of easing:</p>
<pre>// note that most tweens have an easeOut, easeIn and easeInOut constant.

// easeOut
TweenLite.to(box,3 ,{x:400, rotation:180, scaleX:2, scaleY:2, ease:Bounce.easeOut});

// easeIn
TweenLite.to(box,3 ,{x:400, rotation:180, scaleX:2, scaleY:2, ease:Bounce.easeIn});

// easeInOut
TweenLite.to(box,3 ,{x:400, rotation:180, scaleX:2, scaleY:2, ease:Bounce.easeInOut});</pre>
<p>Just understanding the way these few aspects of TweenLite work is enough to start using it for basic applications. At this point you might want to take a break and play around with the <span>TweenLite.to()</span> method.</p>
<h3>Continuing&#8230;</h3>
<p>After playing around a bit, I wondered how to use one type of tween on the x axis and another type of tween on the y. This is easily accomplished with the overwrite property. Try this code in your timeline:</p>
<div>
<div id="actionscript3-1">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> gs.TweenLite;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> fl.<span style="color: #0033ff;">motion</span>.<span style="color: #0033ff;">easing</span>.<span style="color: #0033ff;">*</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">box.<span style="color: #0033ff;">x</span> = <span style="color: #000000;">150</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">box.<span style="color: #0033ff;">y</span> = <span style="color: #000000;">150</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">2</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">x</span>: <span style="color: #000000;">300</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<p>TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">2</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">y</span>: <span style="color: #000000;">300</span>, <span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Bounce</span>.<span style="color: #0033ff;">easeOut</span>, overwrite:<span style="color: #0033ff;">false</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>The above creates a gravity effect by combining the default quadratic tween with the <span>Bounce.easeOut</span> function. Because the overwrite property is false, the second tween doesn&#8217;t overwrite the first tween. Instead, it tweens independently.</p>
<p>After playing with the overwrite property for awhile, I wanted to run another function after the tween was complete. This is done by setting the <span>onComplete</span> property. Try running this code in your timeline:</p>
<div>
<div id="actionscript3-2">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> gs.TweenLite;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> fl.<span style="color: #0033ff;">motion</span>.<span style="color: #0033ff;">easing</span>.<span style="color: #0033ff;">*</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">box.<span style="color: #0033ff;">x</span> = <span style="color: #000000;">150</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">box.<span style="color: #0033ff;">y</span> = <span style="color: #000000;">150</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">2</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">x</span>: <span style="color: #000000;">300</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// here we define our onComplete callback function</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">2</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">y</span>: <span style="color: #000000;">300</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Bounce</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">overwrite:<span style="color: #0033ff;">false</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">onComplete: onJump<span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onJump<span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">y</span>: <span style="color: #000000;">100</span>, <span style="color: #0033ff;">rotation</span>:<span style="color: #000000;">180</span>, <span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Back</span>.<span style="color: #0033ff;">easeOut</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>After doing this I assumed there must be an easy way to pass parameters to your <span>onComplete</span> function. For this task, there&#8217;s another property called <span>onCompleteParams</span> which takes an array of arguments to pass to the <span>onComplete</span> function. This means that you can have a bunch of objects that all use the same <span>onComplete</span> function. So, if we didn&#8217;t want to specifically reference <span>box</span> in our <span>onJump</span> function, we could replace lines 9-16 of the previous script with the following:</p>
<pre>TweenLite.to(box, 2,{y: 300,
           ease: Bounce.easeOut,
           overwrite: false,
           onComplete: onJump,
           onCompleteParams: [box]});

function onJump(mc:MovieClip):void {
	TweenLite.to(mc, 1,{y: 100, rotation:180, ease:Back.easeOut});
}</pre>
<h3>Relative Positioning</h3>
<p>There are three more extremely useful parts of TweenLite worth mentioning. The first one is really simple. If you pass a string to a property rather than a numeric value, that tells TweenLite to use relative positioning. So if you write:</p>
<pre>  TweenLite.to(box, 1,{y: 100});</pre>
<p>Your telling TweenLite to set the y position of <span>box</span> to 100. But if you write:</p>
<pre>  TweenLite.to(box, 1,{y: "100"});</pre>
<p>Your telling TweenLite to add 100 pixels to the current y position of box. Try this code out:</p>
<div>
<div id="actionscript3-3">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> gs.TweenLite;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> fl.<span style="color: #0033ff;">motion</span>.<span style="color: #0033ff;">easing</span>.<span style="color: #0033ff;">*</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">stage</span>.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #0033ff;">MouseEvent</span>.<span style="color: #0033ff;">MOUSE_DOWN</span>, onDown, <span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onDown<span style="color: #000000;">(</span>evt:<span style="color: #0033ff;">MouseEvent</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.to<span style="color: #000000;">(</span>box, <span style="color: #000000;">1</span>, <span style="color: #000000;">{</span><span style="color: #0033ff;">x</span>:<span style="color: #00aa00;">&#8220;40&#8243;</span>, <span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Elastic</span>.<span style="color: #0033ff;">easeOut</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>Every time we click the stage, the box eases 40 pixels to the right.</p>
<h3>Delay</h3>
<p>The delay property simply adds a delay before your tween starts. Consider the following code:</p>
<pre>TweenLite.to(box, 1, {x:300});
TweenLite.to(box, 1, {y:300, overwrite:false, delay:.5})
TweenLite.to(box, .5, {scaleX:.5, overwrite:false, delay:.9})</pre>
<p>We combine three tweens but start them at different times. The result is that the box moves right, then left and then towards the end of the tween, the box scales to 50% width. The delay property is really nice for creating short sequences of events.</p>
<h3>From Method</h3>
<p>The <span>TweenLite.from()</span> method works just like the <span>TweenLite.to()</span> method except that it tweens <em>from</em> the specified values in your third argument rather than <em>to</em> them. I&#8217;ve found this very useful for intro animations. You can just lay all your movie clips on the stage where you want them to end up &#8211; then add some TweenLite code to tween them into position. Take a look at this example:<br />
<em>click on this SWF to replay the animation</em></p>
<div id="swf948f_2" style="text-align: center;"><embed id="id2" type="application/x-shockwave-flash" width="160" height="400" src="http://www.learningactionscript3.com/wp-content/uploads/fakeBanner.swf" name="id2" quality="high" wmode="window" menu="true" allowfullscreen="true"></embed></div>
<p><script type="text/javascript">// <![CDATA[
var vswf = new SWFObject("/wp-content/uploads/fakeBanner.swf", "id2", "160", "400", "9", "#FF0000");
vswf.addParam("wmode", "window");
vswf.addParam("menu", "true");
vswf.addParam("quality", "high");
vswf.addParam("allowFullScreen", "true");
vswf.write("swf948f_2");
// ]]&gt;</script></p>
<p><img style="vertical-align: middle;" title="Download: Fake Banner" src="http://learningactionscript3.com/wp-content/plugins/downloadmanager/images/drive_go.gif" alt="Download: Fake Banner" /> <strong><a title="Download: Fake Banner" href="http://www.learningactionscript3.com/download/32/">Download Fake Banner</a></strong> (11.9 KB, 1,219 hits)</p>
<p>You might want to download the FLA above and take a look at it. All the movie clips have just been placed on the stage exactly where I want them to end up. I then use <span>TweenLite.from()</span> to animate them:</p>
<div>
<div id="actionscript3-4">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> gs.TweenLite;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">import</span> fl.<span style="color: #0033ff;">motion</span>.<span style="color: #0033ff;">easing</span>.<span style="color: #0033ff;">*</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">stop</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// notice this handy tint property, which allows us to </span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// fade from black &#8230; we have to use 0&#215;000001 because if we </span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// pass 0&#215;000000 (or 0) to tint it thinks we want to reset it</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>bg,<span style="color: #000000;">1</span>,<span style="color: #000000;">{</span>tint:0&#215;000001<span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>logoBg, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">scaleX</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">scaleY</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Back</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">delay</span>:.<span style="color: #000000;">5</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>logoBall0, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">scaleX</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">scaleY</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Elastic</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">delay</span>:<span style="color: #000000;">1</span>.<span style="color: #000000;">5</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>logoBall1, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">scaleX</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">scaleY</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Elastic</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">delay</span>:<span style="color: #000000;">1</span>.<span style="color: #000000;">75</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>logoBall2, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">scaleX</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">scaleY</span>:<span style="color: #000000;">0</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Elastic</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">delay</span>:<span style="color: #000000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">TweenLite.from<span style="color: #000000;">(</span>as3, <span style="color: #000000;">1</span>,<span style="color: #000000;">{</span><span style="color: #0033ff;">x</span>:-<span style="color: #000000;">100</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">ease</span>:<span style="color: #0033ff;">Elastic</span>.<span style="color: #0033ff;">easeOut</span>,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">delay</span>:<span style="color: #000000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">stage</span>.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #0033ff;">MouseEvent</span>.<span style="color: #0033ff;">CLICK</span>, onAnimate,</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> onAnimate<span style="color: #000000;">(</span>evt:<span style="color: #0033ff;">MouseEvent</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// reset all clip positions by going to a blank fram and letting</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// the movie loop back to frame 1</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">play</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>It&#8217;s this type of easily scripted animation that sold me on TweenLite. I really like the Flash timeline and use it for static animation 90% of the time &#8211; there are some types of animation that are just better done by hand. However, for simple things like the above example TweenLite is absolutely perfect.</p>
<p><em><br />
It&#8217;s important to note that you&#8217;ll need to go to this link : <a href="http://blog.greensock.com/tweenliteas3/">http://blog.greensock.com/tweenliteas3/</a> and download TweenLite in order for any of the code in the post to work. It&#8217;s also worth taking a look at the excellent documentation that you&#8217;ll find at that same link.</em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=ptn8X2ek9cA:qEv5UvbUl1I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=ptn8X2ek9cA:qEv5UvbUl1I:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=ptn8X2ek9cA:qEv5UvbUl1I:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=ptn8X2ek9cA:qEv5UvbUl1I:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=ptn8X2ek9cA:qEv5UvbUl1I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=ptn8X2ek9cA:qEv5UvbUl1I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=ptn8X2ek9cA:qEv5UvbUl1I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=ptn8X2ek9cA:qEv5UvbUl1I:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/ptn8X2ek9cA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/tweenlite-introduction-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/tweenlite-introduction-as3/</feedburner:origLink></item>
		<item>
		<title>Math.random() * Math.random() in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/iFak4q2q29o/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/math-random-math-random-in-as3/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 03:17:54 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=262</guid>
		<description><![CDATA[



var rand:Number = Math.random() * Math.random() * Math.random();



This is a trick I use when I need more contrast in my random numbers. In this case, the variable rand will get closer to the number 1 significantly less frequently than if you just used Math.random() once.
To illustrate this I created this snippet:





[SWF(width=800, height=600)]
var r:Number = Math.random() [...]]]></description>
			<content:encoded><![CDATA[<div>
<div>
<div id="actionscript-1">
<div style="font-family: monospace;">
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> rand:<span style="color: #0066cc;">Number</span> = <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div>
</div>
</div>
</div>
<p>This is a trick I use when I need more contrast in my random numbers. In this case, the variable rand will get closer to the number 1 significantly less frequently than if you just used Math.random() once.</p>
<p>To illustrate this I created this snippet:</p>
<p><span><br />
</span></p>
<div>
<div id="actionscript-2">
<div style="font-family: monospace;">
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">[</span>SWF<span style="color: #66cc66;">(</span><span style="color: #0066cc;">width</span>=<span style="color: #800000;">800</span>, <span style="color: #0066cc;">height</span>=<span style="color: #800000;">600</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">]</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066cc;">Number</span> = <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> inc:<span style="color: #0066cc;">int</span> = <span style="color: #800000;">0</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> xp:<span style="color: #0066cc;">Number</span> = <span style="color: #800000;">10</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> yp:<span style="color: #0066cc;">Number</span> = <span style="color: #800000;">10</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> count:<span style="color: #0066cc;">int</span> = <span style="color: #800000;">1</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">var</span> compare:Shape = Shape<span style="color: #66cc66;">(</span>addChild<span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">new</span> Shape<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">compare.<span style="color: #006600;">graphics</span>.<span style="color: #0066cc;">lineStyle</span><span style="color: #66cc66;">(</span><span style="color: #800000;">0</span>,0&#215;2222FF<span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">graphics.<span style="color: #0066cc;">lineStyle</span><span style="color: #66cc66;">(</span><span style="color: #800000;">0</span>,0&#215;00000<span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">scaleX = scaleY = <span style="color: #800000;">2</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">addEventListener<span style="color: #66cc66;">(</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onLoop<span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #000000; font-weight: bold;">function</span> onLoop<span style="color: #66cc66;">(</span>evt:Event<span style="color: #66cc66;">)</span>:<span style="color: #0066cc;">void</span> <span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">r =  <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>inc == <span style="color: #800000;">0</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">graphics.<span style="color: #0066cc;">moveTo</span><span style="color: #66cc66;">(</span>xp + inc, yp + <span style="color: #800000;">30</span> &#8211; r <span style="color: #66cc66;">*</span> <span style="color: #800000;">30</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">}</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">graphics.<span style="color: #0066cc;">lineTo</span><span style="color: #66cc66;">(</span>xp + inc, yp + <span style="color: #800000;">30</span> &#8211; r <span style="color: #66cc66;">*</span> <span style="color: #800000;">30</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">}</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">r = <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>inc == <span style="color: #800000;">0</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">compare.<span style="color: #006600;">graphics</span>.<span style="color: #0066cc;">moveTo</span><span style="color: #66cc66;">(</span>xp + inc, yp + <span style="color: #800000;">70</span> &#8211; r <span style="color: #66cc66;">*</span> <span style="color: #800000;">30</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">}</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">compare.<span style="color: #006600;">graphics</span>.<span style="color: #0066cc;">lineTo</span><span style="color: #66cc66;">(</span>xp + inc, yp + <span style="color: #800000;">70</span> &#8211; r <span style="color: #66cc66;">*</span> <span style="color: #800000;">30</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">}</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">inc++;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>inc == <span style="color: #800000;">50</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span></div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">inc = <span style="color: #800000;">0</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">xp = <span style="color: #800000;">10</span> + count <span style="color: #66cc66;">%</span> <span style="color: #800000;">6</span> <span style="color: #66cc66;">*</span> <span style="color: #800000;">60</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">yp = <span style="color: #800000;">10</span> + <span style="color: #0066cc;">int</span><span style="color: #66cc66;">(</span>count <span style="color: #66cc66;">/</span> <span style="color: #800000;">6</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">*</span> <span style="color: #800000;">80</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">r = <span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">*</span><span style="color: #0066cc;">Math</span>.<span style="color: #0066cc;">random</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;">count++;</div>
<div style="margin: 0pt; padding: 0pt; background: transparent none repeat scroll 0% 0%; font-family: monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em; line-height: 1.2em; font-size-adjust: none; font-stretch: normal; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; vertical-align: top;"><span style="color: #66cc66;">}</span></div>
<p><span style="color: #66cc66;">}</span></div>
</div>
</div>
<p>The blue lines plots normal Math.random() and the black lines plots Math.random()*Math.random()*Math.random()</p>
<p><img src="http://actionsnippet.com/wp-content/rand_contrast.gif" alt="" width="495" height="321" /></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iFak4q2q29o:4pfGaUDJUe8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iFak4q2q29o:4pfGaUDJUe8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iFak4q2q29o:4pfGaUDJUe8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iFak4q2q29o:4pfGaUDJUe8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iFak4q2q29o:4pfGaUDJUe8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iFak4q2q29o:4pfGaUDJUe8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iFak4q2q29o:4pfGaUDJUe8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iFak4q2q29o:4pfGaUDJUe8:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/iFak4q2q29o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/math-random-math-random-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/math-random-math-random-in-as3/</feedburner:origLink></item>
		<item>
		<title>describeType in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/hL9yLOnGHzE/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/describetype-in-as3/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 06:06:18 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[describeType]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=251</guid>
		<description><![CDATA[that&#8217;s beautiful.. so much better than typeof.. Though I might also add (if I may), if you want some extremely (almost stupid amount of) detailed info about your class type, you can also use describeType()..
so


var sprite:Sprite = new Sprite();
var spriteDescription:XML = describeType(sprite);
trace (spriteDescription);


traces:

&#60;type name=&#8221;flash.display::Sprite&#8221; base=&#8221;flash.display::DisplayObjectContainer&#8221; isDynamic=&#8221;false&#8221; isFinal=&#8221;false&#8221; isStatic=&#8221;false&#8221;&#62;
  &#60;extendsClass type=&#8221;flash.display::DisplayObjectContainer&#8221;/&#62;
  &#60;extendsClass type=&#8221;flash.display::InteractiveObject&#8221;/&#62;
  [...]]]></description>
			<content:encoded><![CDATA[<p>that&#8217;s beautiful.. so much better than typeof.. Though I might also add (if I may), if you want some extremely (almost stupid amount of) detailed info about your class type, you can also use describeType()..</p>
<p>so</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div><span style="color: #000000; font-weight: bold;">var</span> sprite:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> spriteDescription:<span style="color: #0000ff;">XML</span> = describeType<span style="color: #000000;">(</span>sprite<span style="color: #000000;">)</span>;<br />
<span style="color: #0000ff;">trace</span> <span style="color: #000000;">(</span>spriteDescription<span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>traces:</p>
<div style="margin: 5px 20px 20px;">
&lt;type name=&#8221;flash.display::Sprite&#8221; base=&#8221;flash.display::DisplayObjectContainer&#8221; isDynamic=&#8221;false&#8221; isFinal=&#8221;false&#8221; isStatic=&#8221;false&#8221;&gt;<br />
  &lt;extendsClass type=&#8221;flash.display::DisplayObjectContainer&#8221;/&gt;<br />
  &lt;extendsClass type=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;extendsClass type=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;extendsClass type=&#8221;flash.events::EventDispatcher&#8221;/&gt;<br />
  &lt;extendsClass type=&#8221;Object&#8221;/&gt;<br />
  &lt;implementsInterface type=&#8221;flash.events::IEventDispatcher&#8221;/&gt;<br />
  &lt;implementsInterface type=&#8221;flash.display::IBitmapDrawable&#8221;/&gt;<br />
  &lt;accessor name=&#8221;buttonMode&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;accessor name=&#8221;soundTransform&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.media::SoundTransform&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;accessor name=&#8221;useHandCursor&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;method name=&#8221;stopDrag&#8221; declaredBy=&#8221;flash.display::Sprite&#8221; returnType=&#8221;void&#8221;/&gt;<br />
  &lt;accessor name=&#8221;dropTarget&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::DisplayObject&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;accessor name=&#8221;graphics&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::Graphics&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;accessor name=&#8221;hitArea&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.display::Sprite&#8221; declaredBy=&#8221;flash.display::Sprite&#8221;/&gt;<br />
  &lt;method name=&#8221;startDrag&#8221; declaredBy=&#8221;flash.display::Sprite&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;Boolean&#8221; optional=&#8221;true&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;flash.geom::Rectangle&#8221; optional=&#8221;true&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;swapChildren&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;tabChildren&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221;/&gt;<br />
  &lt;method name=&#8221;getObjectsUnderPoint&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;Array&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.geom::Point&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;getChildAt&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;removeChildAt&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;getChildIndex&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;int&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;areInaccessibleObjectsUnderPoint&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.geom::Point&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;contains&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;mouseChildren&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221;/&gt;<br />
  &lt;method name=&#8221;removeChild&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;setChildIndex&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;addChildAt&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;numChildren&#8221; access=&#8221;readonly&#8221; type=&#8221;int&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221;/&gt;<br />
  &lt;method name=&#8221;addChild&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;getChildByName&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;flash.display::DisplayObject&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;String&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;textSnapshot&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.text::TextSnapshot&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221;/&gt;<br />
  &lt;method name=&#8221;swapChildrenAt&#8221; declaredBy=&#8221;flash.display::DisplayObjectContainer&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;int&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;doubleClickEnabled&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;contextMenu&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.ui::ContextMenu&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;accessibilityImplementation&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.accessibility::AccessibilityImplementation&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;&gt;<br />
    &lt;metadata name=&#8221;Inspectable&#8221;&gt;<br />
      &lt;arg key=&#8221;environment&#8221; value=&#8221;none&#8221;/&gt;<br />
    &lt;/metadata&gt;<br />
  &lt;/accessor&gt;<br />
  &lt;accessor name=&#8221;mouseEnabled&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;focusRect&#8221; access=&#8221;readwrite&#8221; type=&#8221;Object&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;tabIndex&#8221; access=&#8221;readwrite&#8221; type=&#8221;int&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;tabEnabled&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::InteractiveObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;alpha&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;scale9Grid&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.geom::Rectangle&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;name&#8221; access=&#8221;readwrite&#8221; type=&#8221;String&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;filters&#8221; access=&#8221;readwrite&#8221; type=&#8221;Array&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;y&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;rotation&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;scrollRect&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.geom::Rectangle&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;x&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;cacheAsBitmap&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;accessibilityProperties&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.accessibility::AccessibilityProperties&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;globalToLocal&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;flash.geom::Point&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.geom::Point&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;getBounds&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;flash.geom::Rectangle&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;opaqueBackground&#8221; access=&#8221;readwrite&#8221; type=&#8221;Object&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;hitTestPoint&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;Number&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;Number&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;3&#8243; type=&#8221;Boolean&#8221; optional=&#8221;true&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;visible&#8221; access=&#8221;readwrite&#8221; type=&#8221;Boolean&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;mouseX&#8221; access=&#8221;readonly&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;mask&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.display::DisplayObject&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;getRect&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;flash.geom::Rectangle&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;scaleX&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;scaleY&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;root&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::DisplayObject&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;loaderInfo&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::LoaderInfo&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;hitTestObject&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.display::DisplayObject&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;transform&#8221; access=&#8221;readwrite&#8221; type=&#8221;flash.geom::Transform&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;width&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;stage&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::Stage&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;parent&#8221; access=&#8221;readonly&#8221; type=&#8221;flash.display::DisplayObjectContainer&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;height&#8221; access=&#8221;readwrite&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;localToGlobal&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221; returnType=&#8221;flash.geom::Point&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.geom::Point&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;accessor name=&#8221;mouseY&#8221; access=&#8221;readonly&#8221; type=&#8221;Number&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;accessor name=&#8221;blendMode&#8221; access=&#8221;readwrite&#8221; type=&#8221;String&#8221; declaredBy=&#8221;flash.display::DisplayObject&#8221;/&gt;<br />
  &lt;method name=&#8221;removeEventListener&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;String&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;Function&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;3&#8243; type=&#8221;Boolean&#8221; optional=&#8221;true&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;addEventListener&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;void&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;String&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;2&#8243; type=&#8221;Function&#8221; optional=&#8221;false&#8221;/&gt;<br />
    &lt;parameter index=&#8221;3&#8243; type=&#8221;Boolean&#8221; optional=&#8221;true&#8221;/&gt;<br />
    &lt;parameter index=&#8221;4&#8243; type=&#8221;int&#8221; optional=&#8221;true&#8221;/&gt;<br />
    &lt;parameter index=&#8221;5&#8243; type=&#8221;Boolean&#8221; optional=&#8221;true&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;toString&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;String&#8221;/&gt;<br />
  &lt;method name=&#8221;dispatchEvent&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;flash.events::Event&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;hasEventListener&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;String&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
  &lt;method name=&#8221;willTrigger&#8221; declaredBy=&#8221;flash.events::EventDispatcher&#8221; returnType=&#8221;Boolean&#8221;&gt;<br />
    &lt;parameter index=&#8221;1&#8243; type=&#8221;String&#8221; optional=&#8221;false&#8221;/&gt;<br />
  &lt;/method&gt;<br />
&lt;/type&gt;
</div>
<p>Enjoy <img src='http://blog.flashbanneronline.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=hL9yLOnGHzE:qoB5l_f2nfk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=hL9yLOnGHzE:qoB5l_f2nfk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=hL9yLOnGHzE:qoB5l_f2nfk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=hL9yLOnGHzE:qoB5l_f2nfk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=hL9yLOnGHzE:qoB5l_f2nfk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=hL9yLOnGHzE:qoB5l_f2nfk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=hL9yLOnGHzE:qoB5l_f2nfk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=hL9yLOnGHzE:qoB5l_f2nfk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/hL9yLOnGHzE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/describetype-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/describetype-in-as3/</feedburner:origLink></item>
		<item>
		<title>Writing Inline XML in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/iIBMEq61FLI/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/writing-inline-xml-in-as3/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 02:15:04 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Inline]]></category>
		<category><![CDATA[Writing]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=248</guid>
		<description><![CDATA[In ActionScript 3, you can define XML variables using inline XML in your script. You don&#8217;t even need to enclose it in Strings like you did in previous versions of ActionScript. The ActionScript 3 compiler will automatically parse the XML in the code and recognize when it stops and when normal AS code starts.


var myXml:XML [...]]]></description>
			<content:encoded><![CDATA[<div id="post_message_1900450">In ActionScript 3, you can define XML variables using inline XML in your script. You don&#8217;t even need to enclose it in Strings like you did in previous versions of ActionScript. The ActionScript 3 compiler will automatically parse the XML in the code and recognize when it stops and when normal AS code starts.</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div><span style="color: #000000; font-weight: bold;">var</span> myXml:<span style="color: #0000ff;">XML</span> =<br />
&lt;body&gt;<br />
&lt;!&#8211; comment &#8211;&gt;<br />
text1<br />
&lt;a&gt;<br />
&lt;b&gt;text2&lt;/b&gt;<br />
&lt;/a&gt;<br />
&lt;/body&gt;;</div>
</div>
</div>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iIBMEq61FLI:vh-C9TZY8aw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iIBMEq61FLI:vh-C9TZY8aw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iIBMEq61FLI:vh-C9TZY8aw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iIBMEq61FLI:vh-C9TZY8aw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iIBMEq61FLI:vh-C9TZY8aw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iIBMEq61FLI:vh-C9TZY8aw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=iIBMEq61FLI:vh-C9TZY8aw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=iIBMEq61FLI:vh-C9TZY8aw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/iIBMEq61FLI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/writing-inline-xml-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/writing-inline-xml-in-as3/</feedburner:origLink></item>
		<item>
		<title>Events and Event Types in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/AMmuP8ZTOCs/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/events-and-event-types-in-as3/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 04:03:54 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[MouseEvent]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=245</guid>
		<description><![CDATA[Event objects used with EventDispatcher in ActionScript 3 are a little less generic than those used with ActionScript 2. In AS 3, each event object has its own class. The most common event classes are Event (flash.events.Event) for general events and MouseEvent (flash.events.MouseEvent) for events associated with the mouse. Other event classes can be found [...]]]></description>
			<content:encoded><![CDATA[<div id="post_message_1899698">Event objects used with EventDispatcher in ActionScript 3 are a little less generic than those used with ActionScript 2. In AS 3, each event object has its own class. The most common event classes are Event (<a href="http://livedocs.macromedia.com/flex/2/langref/flash/events/Event.html" target="_blank">flash.events.Event</a>) for general events and MouseEvent (<a href="http://livedocs.macromedia.com/flex/2/langref/flash/events/MouseEvent.html" target="_blank">flash.events.MouseEvent</a>) for events associated with the mouse. Other event classes can be found in the flash.events package, all of which inherit from Event.</p>
<p>When using EventDispatcher.dispatchEvent(), you pass in an Event instance that is specific to the event being dispatched. The type of event dispatched is defined within the Event instance used. For example, dispatching an &#8220;enterFrame&#8221; event would mean using dispatchEvent with an Event instance instantiated with the type &#8220;enterFrame&#8221;.</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div>dispatchEvent<span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;enterFrame&#8221;</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>When an event handler is executed as a result of this event, that event object is passed into the function as a single argument. Properties from that event can then be extracted to learn more about the event that occured. For example, the type property from the Event class tells which event was dispatched.</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div>addEventListener<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;enterFrame&#8221;</span>, eventHandler<span style="color: #000000;">)</span>;<br />
dispatchEvent<span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;enterFrame&#8221;</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;<br />
&#8230;<br />
<span style="color: #0000ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> eventHandler<span style="color: #000000;">(</span>event:Event<span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">trace</span><span style="color: #000000;">(</span>event.<span style="color: #0000ff;">type</span><span style="color: #000000;">)</span>; <span style="color: #808080; font-style: italic;">// &#8220;enterFrame&#8221;</span><br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<p>Though event types are strings, all common Flash events are available in Flash through static constants of the Event classes. The &#8220;enterFrame&#8221; event type, for example, is accessible using Event.ENTER_FRAME. Mouse events are within the MouseEvent class. Click events, for example, are MouseEvent.CLICK. These constants are prefered over their string representations.</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div>addEventListener<span style="color: #000000;">(</span>Event.<span style="color: #000080;">ENTER_FRAME</span>, eventHandler<span style="color: #000000;">)</span>;<br />
dispatchEvent<span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #000000;">(</span>Event.<span style="color: #000080;">ENTER_FRAME</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>When making your custom Events, you can use the Event object with a custom type or alternatively, extend the Event class creating a new kind of Event instance to be used with your events.</p></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=AMmuP8ZTOCs:IPpPjXVzjKI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=AMmuP8ZTOCs:IPpPjXVzjKI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=AMmuP8ZTOCs:IPpPjXVzjKI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=AMmuP8ZTOCs:IPpPjXVzjKI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=AMmuP8ZTOCs:IPpPjXVzjKI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=AMmuP8ZTOCs:IPpPjXVzjKI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=AMmuP8ZTOCs:IPpPjXVzjKI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=AMmuP8ZTOCs:IPpPjXVzjKI:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/AMmuP8ZTOCs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/events-and-event-types-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/events-and-event-types-in-as3/</feedburner:origLink></item>
		<item>
		<title>EventDispatcher in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/qKQErf-xMUQ/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/eventdispatcher-in-as3/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 03:10:51 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[dispatchEvent]]></category>
		<category><![CDATA[EventDispatcher]]></category>
		<category><![CDATA[hasEventListener]]></category>
		<category><![CDATA[removeEventListener]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=242</guid>
		<description><![CDATA[ActionScript 3 uses the EventDispatcher (flash.events.EventDispatcher) class for all event handling. This class was available in ActionScript 2, but it existed as an external class in the mx framework. Now, it is built into the player (and in being so, improves performance).
Whenever you want to create an event handler to be called during a certain [...]]]></description>
			<content:encoded><![CDATA[<p>ActionScript 3 uses the EventDispatcher (<a href="http://livedocs.macromedia.com/flex/2/langref/flash/events/EventDispatcher.html" target="_blank">flash.events.EventDispatcher</a>) class for all event handling. This class was available in ActionScript 2, but it existed as an external class in the mx framework. Now, it is built into the player (and in being so, improves performance).</p>
<p>Whenever you want to create an event handler to be called during a certain event, whether it be every frame (enterFrame event), or at the press of a button (mouseDown event), in AS 3, you will need to use EventDispatcher. This means there are no more onEnterFrame of onPress functions you can define that will automatically handle these events, nor are there any simple addListener methods for generalized event listening. EventDispatcher and addEventListener (and related methods) does it all.</p>
<p>Methods</p>
<ul>
<li><strong>addEventListener</strong>(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void</li>
<li><strong>dispatchEvent</strong>(event:Event):Boolean</li>
<li><strong>hasEventListener</strong>(type:String):Boolean</li>
<li><strong>removeEventListener</strong>(type:String, listener:Function, useCapture:Boolean = false):void</li>
<li><strong>willTrigger</strong>(type:String):Boolean</li>
</ul>
<p>Note that addEventListener only takes functions as listeners, not objects. Also remember that class methods are bound to their instances so when used as listeners, &#8216;this&#8217; in the event call still references the orginal class instance no matter what object dispatched the event.</p>
<p>Basic Example:</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div>package <span style="color: #000000;">{</span><span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">display</span>.<span style="color: #000080;">Sprite</span>;<br />
<span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">events</span>.<span style="color: #000080;">Event</span>;</p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyDispatcher <span style="color: #0000ff;">extends</span> Sprite <span style="color: #000000;">{</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyDispatcher<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span><br />
addEventListener<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;customEvent&#8221;</span>, handleEvent<span style="color: #000000;">)</span>;<br />
dispatchEvent<span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;customEvent&#8221;</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleEvent<span style="color: #000000;">(</span>event:Event<span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">trace</span><span style="color: #000000;">(</span>event.<span style="color: #0000ff;">type</span><span style="color: #000000;">)</span>; <span style="color: #808080; font-style: italic;">// &#8220;customEvent&#8221;</span><br />
<span style="color: #000000;">}</span><br />
<span style="color: #000000;">}</span><br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<p>By extending the EventDispatcher class or any class that inherits from it like Sprite (all DisplayObjects are inherently EventDispatchers), your class gains access to the EventDispatcher methods. Then, other instances (or the class instance itself) can add methods to instances of that class using addEventListener and in turn they can call those events through dispatchEvent.</p>
<p>If there is some reason your class cannot inherit from the EventDispatcher class (for example, if its already inheriting from another class which does not inherit from EventDispatcher), then you can use the EventDispatcher constructor to intialize your class instance with the methods of EventDispatcher via aggregation (composition). Just make sure you implement the IEventDispatcher interface (flash.events.IEventDispatcher). Ex:</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div>package <span style="color: #000000;">{</span><span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">display</span>.<span style="color: #000080;">Sprite</span>;<br />
<span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">events</span>.<span style="color: #000080;">Event</span>;</p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyDispatcher <span style="color: #0000ff;">extends</span> Sprite <span style="color: #000000;">{</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyDispatcher<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span><br />
<span style="color: #000000; font-weight: bold;">var</span> dispatcher:CustomDispatcher = <span style="color: #000000; font-weight: bold;">new</span> CustomDispatcher<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
dispatcher.<span style="color: #000080;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;customEvent&#8221;</span>, handleEvent<span style="color: #000000;">)</span>;<br />
dispatcher.<span style="color: #000080;">dispatchEvent</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;customEvent&#8221;</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleEvent<span style="color: #000000;">(</span>event:Event<span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">trace</span><span style="color: #000000;">(</span>event.<span style="color: #0000ff;">type</span><span style="color: #000000;">)</span>; <span style="color: #808080; font-style: italic;">// &#8220;customEvent&#8221;</span><br />
<span style="color: #000000;">}</span><br />
<span style="color: #000000;">}</span><br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">events</span>.<span style="color: #000080;">Event</span>;<br />
<span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">events</span>.<span style="color: #000080;">EventDispatcher</span>;<br />
<span style="color: #0000ff;">import</span> flash.<span style="color: #000080;">events</span>.<span style="color: #000080;">IEventDispatcher</span>;</p>
<p><span style="color: #000000; font-weight: bold;">class</span> CustomDispatcher <span style="color: #0000ff;">implements</span> IEventDispatcher <span style="color: #000000;">{</span></p>
<p><span style="color: #0000ff;">private</span> <span style="color: #000000; font-weight: bold;">var</span> eventDispatcher:EventDispatcher;</p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CustomDispatcher<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span><br />
eventDispatcher = <span style="color: #000000; font-weight: bold;">new</span> EventDispatcher<span style="color: #000000;">(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addEventListener<span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>:<span style="color: #0000ff;">String</span>, listener:<span style="color: #000000; font-weight: bold;">Function</span>, useCapture:<span style="color: #0000ff;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>, priority:<span style="color: #0000ff;">int</span> = <span style="color: #000080;">0</span>, useWeakReference:<span style="color: #0000ff;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
eventDispatcher.<span style="color: #000080;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>, listener, useCapture, priority, useWeakReference<span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span><br />
<span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dispatchEvent<span style="color: #000000;">(</span>event:Event<span style="color: #000000;">)</span>:<span style="color: #0000ff;">Boolean</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">return</span> eventDispatcher.<span style="color: #000080;">dispatchEvent</span><span style="color: #000000;">(</span>event<span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasEventListener<span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>:<span style="color: #0000ff;">String</span><span style="color: #000000;">)</span>:<span style="color: #0000ff;">Boolean</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">return</span> eventDispatcher.<span style="color: #000080;">hasEventListener</span><span style="color: #000000;">(</span><span style="color: #0000ff;">type</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> removeEventListener<span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>:<span style="color: #0000ff;">String</span>, listener:<span style="color: #000000; font-weight: bold;">Function</span>, useCapture:<span style="color: #0000ff;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
eventDispatcher.<span style="color: #000080;">removeEventListener</span><span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>, listener, useCapture<span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #0000ff;">public</span> <span style="color: #000000; font-weight: bold;">function</span> willTrigger<span style="color: #000000;">(</span><span style="color: #0000ff;">type</span>:<span style="color: #0000ff;">String</span><span style="color: #000000;">)</span>:<span style="color: #0000ff;">Boolean</span> <span style="color: #000000;">{</span><br />
<span style="color: #0000ff;">return</span> eventDispatcher.<span style="color: #000080;">willTrigger</span><span style="color: #000000;">(</span><span style="color: #0000ff;">type</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span><br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<p>The CustomDispatcher helper class above doesn&#8217;t inherit from EventDispatcher but uses aggregation to obtain EventDispatcher functionality through an instance of EventDispatcher initialized in the constructor.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=qKQErf-xMUQ:cp1t9zIDX8U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=qKQErf-xMUQ:cp1t9zIDX8U:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=qKQErf-xMUQ:cp1t9zIDX8U:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=qKQErf-xMUQ:cp1t9zIDX8U:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=qKQErf-xMUQ:cp1t9zIDX8U:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=qKQErf-xMUQ:cp1t9zIDX8U:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=qKQErf-xMUQ:cp1t9zIDX8U:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=qKQErf-xMUQ:cp1t9zIDX8U:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/qKQErf-xMUQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/eventdispatcher-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/eventdispatcher-in-as3/</feedburner:origLink></item>
		<item>
		<title>Loading Text and XML with URLLoader in AS3</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/9xatlWdMGiM/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/loading-text-and-xml-with-urlloader-in-as3/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 04:20:17 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Loading]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[URLLoader]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=239</guid>
		<description><![CDATA[In previous versions of ActionScript, there were a couple of classes who had the capability of loading external text, namely LoadVars and XML. The loading responsibilities of these classes has moved to one single class in ActionScript 3, URLLoader (flash.net.URLLoader). This class is a lot like LoadVars. The big difference is that it is used [...]]]></description>
			<content:encoded><![CDATA[<p>In previous versions of ActionScript, there were a couple of classes who had the capability of loading external text, namely LoadVars and XML. The loading responsibilities of these classes has moved to one single class in ActionScript 3, URLLoader (<a href="http://livedocs.macromedia.com/flex/2/langref/flash/net/URLLoader.html" target="_blank">flash.net.URLLoader</a>). This class is a lot like LoadVars. The big difference is that it is used for XML since the responsibility of loading XML from an external source has been removed from the XML class. Instead, you would load the text with URLLoader and then give that text to an XML object for parsing.</p>
<p>Like LoadVars, URLLoader has a load() method that is used to load text from an external source. This accepts 1 argument, a URLRequest instance (NOT a URL string). You can then use events from URLLoader to determine when the loading is complete. When complete, the text loaded is available in the data property of URLLoader.</p>
<p>Example:</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div><span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader;<br />
<span style="color: #808080; font-style: italic;">// &#8230;</span><br />
loader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
loader.<span style="color: #000080;">addEventListener</span><span style="color: #000000;">(</span>Event.<span style="color: #000080;">COMPLETE</span>, xmlLoaded<span style="color: #000000;">)</span>;</p>
<p><span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;file.xml&#8221;</span><span style="color: #000000;">)</span>;<br />
loader.<span style="color: #0000ff;">load</span><span style="color: #000000;">(</span>request<span style="color: #000000;">)</span>;<br />
<span style="color: #808080; font-style: italic;">//&#8230;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> xmlLoaded<span style="color: #000000;">(</span>event:Event<span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
    <span style="color: #000000; font-weight: bold;">var</span> myXML:<span style="color: #0000ff;">XML</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0000ff;">XML</span><span style="color: #000000;">(</span>loader.<span style="color: #0000ff;">data</span><span style="color: #000000;">)</span>;<br />
    <span style="color: #808080; font-style: italic;">//&#8230;</span><br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=9xatlWdMGiM:SabzLv6YwSc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=9xatlWdMGiM:SabzLv6YwSc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=9xatlWdMGiM:SabzLv6YwSc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=9xatlWdMGiM:SabzLv6YwSc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=9xatlWdMGiM:SabzLv6YwSc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=9xatlWdMGiM:SabzLv6YwSc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=9xatlWdMGiM:SabzLv6YwSc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=9xatlWdMGiM:SabzLv6YwSc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/9xatlWdMGiM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/loading-text-and-xml-with-urlloader-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/loading-text-and-xml-with-urlloader-in-as3/</feedburner:origLink></item>
		<item>
		<title>AVM2 (AS3) to AVM1 (AS2/1) Communication via LocalConnection</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/OD9qmrlAdxQ/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/avm2-as3-to-avm1-as2as1-communication-via-localconnection/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 07:10:33 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS1]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AVM1]]></category>
		<category><![CDATA[AVM2]]></category>
		<category><![CDATA[Communication]]></category>
		<category><![CDATA[LocalConnection]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=255</guid>
		<description><![CDATA[The ActionScript virtual machine that runs ActionScript 3 code (AVM2) is completely different from the ActionScript virtual machin that runs ActionScript 1 and ActionScript 2 code (AVM1). Because of this, you cannot call commands in an AVM1 movie from and AVM2 movie or vise versa. The virtual machines just are not compatible in that respect [...]]]></description>
			<content:encoded><![CDATA[<p>The ActionScript virtual machine that runs ActionScript 3 code (AVM2) is completely different from the ActionScript virtual machin that runs ActionScript 1 and ActionScript 2 code (AVM1). Because of this, you cannot call commands in an AVM1 movie from and AVM2 movie or vise versa. The virtual machines just are not compatible in that respect and mostly run in their own kind of shell that allows it to only interact with code being played back in that same virtual machine. What that boils down to is that ActionScript 3 cannot talk to AS1 or AS2 &#8211; at least not directly.</p>
<p>One thing these two virtual machines have in common is their implementation of LocalConnection. Both virtual machines deal with local connections in essentially the same way &#8211; enough that local connections in AVM1 can receive events from AVM2 and vise versa. So should you come into a situation where you would need a movie published in ActionScript 3 to communicate with a movie published in ActionScript 1 or 2, using local connection is the way to go.</p>
<ul>
<li><a href="http://livedocs.macromedia.com/flash/8/main/00002338.html" target="_blank">LocalConnection AS2</a></li>
<li><a href="http://livedocs.macromedia.com/flex/2/langref/flash/net/LocalConnection.html" target="_blank">LocalConnection AS3 (flash.net.LocalConnection)</a></li>
</ul>
<p>Example:</p>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div><span style="color: #808080; font-style: italic;">// ActionScript 2 file, AS2animation.fla</span><br />
<span style="color: #808080; font-style: italic;">// one movie clip animation named animation_mc on the timeline</span></p>
<p><span style="color: #808080; font-style: italic;">// local connection instance to receive events</span><br />
<span style="color: #000000; font-weight: bold;">var</span> AVM_lc:<span style="color: #0000ff;">LocalConnection</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0000ff;">LocalConnection</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</p>
<p><span style="color: #808080; font-style: italic;">// stopAnimation event handler</span><br />
AVM_lc.<span style="color: #000080;">stopAnimation</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">{</span><br />
animation_mc.<span style="color: #0000ff;">stop</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></p>
<p><span style="color: #808080; font-style: italic;">// listen for events for &#8220;AVM2toAVM1&#8243;</span><br />
AVM_lc.<span style="color: #0000ff;">connect</span><span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;AVM2toAVM1&#8243;</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<div style="margin: 5px 20px 20px;">
<div style="text-align: left;" dir="ltr">
<div><span style="color: #808080; font-style: italic;">// ActionScript 3 file, AS3Loader.fla</span></p>
<p><span style="color: #808080; font-style: italic;">// local connection instance to communicate to AVM1 movie</span><br />
<span style="color: #000000; font-weight: bold;">var</span> AVM_lc:<span style="color: #0000ff;">LocalConnection</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0000ff;">LocalConnection</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</p>
<p><span style="color: #808080; font-style: italic;">// loader loads AVM1 movie</span><br />
<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
loader.<span style="color: #0000ff;">load</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;AS2animation.swf&#8221;</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;<br />
addChild<span style="color: #000000;">(</span>loader<span style="color: #000000;">)</span>;</p>
<p><span style="color: #808080; font-style: italic;">// when AVM1 movie is clicked, call stopPlayback</span><br />
loader.<span style="color: #000080;">addEventListener</span><span style="color: #000000;">(</span>MouseEvent.<span style="color: #000080;">CLICK</span>, stopPlayback<span style="color: #000000;">)</span>;</p>
<p><span style="color: #000000; font-weight: bold;">function</span> stopPlayback<span style="color: #000000;">(</span>event:MouseEvent<span style="color: #000000;">)</span>:<span style="color: #0000ff;">void</span> <span style="color: #000000;">{</span><br />
<span style="color: #808080; font-style: italic;">// send stopAnimation event to &#8220;AVM2toAVM1&#8243; connection</span><br />
AVM_lc.<span style="color: #0000ff;">send</span><span style="color: #000000;">(</span><span style="color: #ff0000;">&#8220;AVM2toAVM1&#8243;</span>, <span style="color: #ff0000;">&#8220;stopAnimation&#8221;</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<p>The AS3 movie loads the AS2 movie into a Loader instance and places it on the screen. As it plays, the user can click the animation which calls stopPlayback sending the &#8220;stopAnimation&#8221; event to the local connection named &#8220;AVM2toAVM1&#8243;. The AS2 movie is then able to receive that event in its stopAnimation event handler and tell the animation_mc clip to stop.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=OD9qmrlAdxQ:oiVPsfyJdtM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=OD9qmrlAdxQ:oiVPsfyJdtM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=OD9qmrlAdxQ:oiVPsfyJdtM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=OD9qmrlAdxQ:oiVPsfyJdtM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=OD9qmrlAdxQ:oiVPsfyJdtM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=OD9qmrlAdxQ:oiVPsfyJdtM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=OD9qmrlAdxQ:oiVPsfyJdtM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=OD9qmrlAdxQ:oiVPsfyJdtM:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/OD9qmrlAdxQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/avm2-as3-to-avm1-as2as1-communication-via-localconnection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/avm2-as3-to-avm1-as2as1-communication-via-localconnection/</feedburner:origLink></item>
		<item>
		<title>Tricks and Experiments , AS3 Tips</title>
		<link>http://feedproxy.google.com/~r/flashbanneronlineblog/~3/13dV0BRIzJs/</link>
		<comments>http://blog.flashbanneronline.com/2009/10/tricks-and-experiments-as3-tips/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 05:09:17 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[beginFill]]></category>
		<category><![CDATA[drawRect]]></category>
		<category><![CDATA[endFill]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=265</guid>
		<description><![CDATA[As you read each of the following descriptions, consider opening Flash, pasting the code into timeline script and testing the swf.
FileReference.save()


var file:FileReference = new FileReference();
stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
function onClick(evt:MouseEvent):void {file.save(&#8220;some text.\nsome more text&#8221;, &#8220;actionsnippet.txt&#8221;);
}


This is one of my favorite features of Flash 10. We can save any kind of file to a user&#8217;s computer [...]]]></description>
			<content:encoded><![CDATA[<p><em>As you read each of the following descriptions, consider opening Flash, pasting the code into timeline script and testing the swf.</em></p>
<h3>FileReference.save()</h3>
<div>
<div id="actionscript3-1">
<div><span style="color: #0033ff;">var</span> file:<span style="color: #0033ff;">FileReference</span> = <span style="color: #0033ff;">new</span> <span style="color: #0033ff;">FileReference</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;<br />
<span style="color: #0033ff;">stage</span>.<span style="color: #0033ff;">addEventListener</span><span style="color: #000000;">(</span><span style="color: #0033ff;">MouseEvent</span>.<span style="color: #0033ff;">CLICK</span>, onClick, <span style="color: #0033ff;">false</span>, <span style="color: #000000;">0</span>, <span style="color: #0033ff;">true</span><span style="color: #000000;">)</span>;<br />
<span style="color: #0033ff;">function</span> onClick<span style="color: #000000;">(</span>evt:<span style="color: #0033ff;">MouseEvent</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span>file.<span style="color: #0033ff;">save</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;some text.<span>\n</span>some more text&#8221;</span>, <span style="color: #00aa00;">&#8220;actionsnippet.txt&#8221;</span><span style="color: #000000;">)</span>;<br />
<span style="color: #000000;">}</span></div>
</div>
</div>
<p>This is one of my favorite features of Flash 10. We can save any kind of file to a user&#8217;s computer using the <span>FileReference.save()</span> method. Its first argument is for the data to put in the file. This can be a <span>String</span>, <span>ByteArray</span>, or <span>XML</span> object. The second argument is the name of the file.</p>
<p>If you paste this code in your timeline all you need to do is click the stage and you&#8217;ll get a dialogue asking where you would like to save the file &#8220;actionsnippet.txt&#8221;.</p>
<p><span id="more-61"> </span></p>
<h3>Quick Alphabet Array</h3>
<div>
<div id="actionscript3-2">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">var</span> alphabet:<span style="color: #0033ff;">Array</span> = <span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;abcdefghijklmnopqrstuvwxyz&#8221;</span><span style="color: #000000;">)</span>.<span style="color: #0033ff;">split</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;&#8221;</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span><span style="color: #00aa00;">&#8220;this is the letter b&#8230;&#8221;</span>, alphabet<span style="color: #000000;">[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span>alphabet<span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>outputs:</p>
<pre>this is the letter b... b
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z</pre>
<p>This snippet can be used to quickly create an array of letters. In this case we create an array out of the alphabet. The only thing you need to know to understand this snippet is the <span>String.split()</span> method. <span>String.split()</span> takes two arguments: a delimiter and a limit value. In our case we just use the delimiter argument. A more normal example of <span>String.split()</span> might look like this:</p>
<pre>var names:String = "Jon, James, Jeff, Joe, Kim, Kip";

// To get all these names into an array we can use the String.split() method:

var allNames:Array = names.split(", ");</pre>
<p>Here we have a <span>String</span> called <span>names</span> that contains six different names. The names are delineated by a comma and a space <span>&#8220;, &#8220;</span> so this is what we pass to the delimiter argument of the <span>String.split()</span> method. <span>String.split()</span> then returns an array where &#8220;Jon&#8221; is the first value, &#8220;James&#8221; is the second value, etc&#8230;.</p>
<p>An interesting feature of <span>String.split()</span> is that if you pass an empty string as the delimiter argument, the string will get split after ever character. This is how the original snippet works. Because we don&#8217;t supply a delimiter, we end up with an array filled with the alphabet.</p>
<p>There are many different ways to use <span>String.split()</span>. The limit argument could be used so that the <span>String</span> is only split a given number of times. <span>String.split()</span> can also be used with regular expressions.</p>
<p>As a side note, Ted from lazylady.se pointed out that this snippet could be written without parenthesis:</p>
<pre>var alphabet:Array = "abcdefghijklmnopqrstuvwxyz".split("");</pre>
<h3>Random Choice</h3>
<div>
<div id="actionscript3-3">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> randomChoice<span style="color: #000000;">(</span>&#8230;args:<span style="color: #0033ff;">Array</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">*</span><span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">return</span> args<span style="color: #000000;">[</span><span style="color: #0033ff;">int</span><span style="color: #000000;">(</span><span style="color: #0033ff;">Math</span>.<span style="color: #0033ff;">random</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>*args.<span style="color: #0033ff;">length</span><span style="color: #000000;">)</span><span style="color: #000000;">]</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// choose randomly from a number of different values</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">var</span> val:<span style="color: #0033ff;">*</span> = randomChoice<span style="color: #000000;">(</span><span style="color: #000000;">10</span>, <span style="color: #00aa00;">&#8220;Hello&#8221;</span>, <span style="color: #00aa00;">&#8220;0xFF0000&#8243;</span>, <span style="color: #000000;">1000</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// choose a random color (in this case red, green or blue)</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">var</span> randColor:<span style="color: #0033ff;">uint</span> = randomChoice<span style="color: #000000;">(</span>0xFF0000, 0&#215;00FF00, 0&#215;0000FF<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span>val<span style="color: #000000;">)</span>;</div>
<p><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span>randColor<span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>The function <span>randomChoice()</span> takes any number of arguments and returns one of them randomly. This is useful for color values, arbitrary sets of numbers or sets of mixed datatypes. Let&#8217;s take a look at how it works.</p>
<p>Using <span>Math.random()</span> to generate numbers in a given range is easy:</p>
<div>
<div id="actionscript3-4">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// 0 to 9</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span><span style="color: #0033ff;">int</span><span style="color: #000000;">(</span><span style="color: #0033ff;">Math</span>.<span style="color: #0033ff;">random</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>*<span style="color: #000000;">10</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// -50 to 50</span></div>
<p><span style="color: #0033ff;">trace</span><span style="color: #000000;">(</span><span style="color: #0033ff;">Math</span>.<span style="color: #0033ff;">round</span><span style="color: #000000;">(</span><span style="color: #0033ff;">Math</span>.<span style="color: #0033ff;">random</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>*<span style="color: #000000;">100</span><span style="color: #000000;">)</span> &#8211; <span style="color: #000000;">50</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>But what if you only wanted <span>Math.random()</span> to give you one of the following numbers 10, 108, 200 or .5? One way to do this is to create an array of those values and then set a random index value based on the length of the array:</p>
<pre>var vals:Array = [10, 108, 200, .5];

// index of vals is 0 - 3 (or the length of vals - 1)
trace(vals[int(Math.random() * vals.length)]);</pre>
<p>The above will trace out one of the values from the array <span>vals</span>. This works nicely, but writing a function to handle it is a bit cleaner. The <span>randomChoice()</span> function uses the exact same technique shown above. The key is that we make use of the AS3 <span>&#8230;rest</span> parameter (&#8230;) for our Array. When used, the <span>&#8230;rest</span> parameter should always be the last argument in your function because it tells Flash to allow any number of additional arguments to be passed into the function. These additional arguments will then be treated as an array. In the case of the <span>randomChoice()</span> function we only need to define one argument:</p>
<pre>function randomChoice(...args):* {</pre>
<p>The information passed into <span>args</span> is treated as an array and we&#8217;re able to use <span>Math.random()</span> to grab a value from that array. Since arrays can have mixed data types, the <span>randomChoice()</span> function return value is typed using * (wildcard). This means it can return any datatype <span>String, MovieClip, uint, int, Number</span> etc&#8230; Before moving on you may consider playing around with the <span>randomChoice()</span> function for a few minutes.</p>
<h3>&#8220;with&#8221; Statement and the Graphics Class</h3>
<div>
<div id="actionscript3-5">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">with</span><span style="color: #000000;">(</span><span style="color: #0033ff;">graphics</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">beginFill</span><span style="color: #000000;">(</span>0xFF0000<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">drawRect</span><span style="color: #000000;">(</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">100</span>, <span style="color: #000000;">100</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">endFill</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">beginFill</span><span style="color: #000000;">(</span>0xFFFF00<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">drawRect</span><span style="color: #000000;">(</span><span style="color: #000000;">10</span>, <span style="color: #000000;">10</span>, <span style="color: #000000;">80</span>, <span style="color: #000000;">80</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">endFill</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">beginFill</span><span style="color: #000000;">(</span>0&#215;0000FF<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">drawCircle</span><span style="color: #000000;">(</span><span style="color: #000000;">50</span>, <span style="color: #000000;">50</span>, <span style="color: #000000;">40</span><span style="color: #000000;">)</span>;</div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>This snippet shows how using <span>with</span> statements in conjunction with <span>Graphics</span> class method calls can save you some typing and improve code readability. We talked about this in the book on page 142-143.</p>
<p>A less-readable way to do this in one line looks like this:</p>
<p><span><br />
</span></p>
<div>
<div id="actionscript3-6">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// draw red circle</span></div>
<p><span style="color: #0033ff;">with</span> <span style="color: #000000;">(</span><span style="color: #0033ff;">graphics</span><span style="color: #000000;">)</span> <span style="color: #0033ff;">beginFill</span><span style="color: #000000;">(</span>0xFF0000<span style="color: #000000;">)</span>, <span style="color: #0033ff;">drawCircle</span><span style="color: #000000;">(</span><span style="color: #000000;">200</span>, <span style="color: #000000;">100</span>, <span style="color: #000000;">30</span><span style="color: #000000;">)</span>;</div>
</div>
</div>
<p>This is often less readable than the multi-line approach so in cases with three or more method calls I&#8217;ll usually choose the multi-line with statement.</p>
<h3>Set Multiple Properties of an Object</h3>
<div>
<div id="actionscript3-7">
<div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">var</span> s:<span style="color: #0033ff;">Sprite</span> = <span style="color: #0033ff;">new</span> <span style="color: #0033ff;">Sprite</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">s.<span style="color: #0033ff;">graphics</span>.<span style="color: #0033ff;">beginFill</span><span style="color: #000000;">(</span>0&#215;000000<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">s.<span style="color: #0033ff;">graphics</span>.<span style="color: #0033ff;">drawRect</span><span style="color: #000000;">(</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, <span style="color: #000000;">10</span>, <span style="color: #000000;">10</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">addChild</span><span style="color: #000000;">(</span>s<span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// set some properties</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">setProps<span style="color: #000000;">(</span>s, <span style="color: #000000;">{</span><span style="color: #0033ff;">x</span>:<span style="color: #000000;">100</span>, <span style="color: #0033ff;">y</span>:<span style="color: #000000;">100</span>, <span style="color: #0033ff;">scaleX</span>:<span style="color: #000000;">2</span>, <span style="color: #0033ff;">scaleY</span>:<span style="color: #000000;">2</span>, <span style="color: #0033ff;">rotation</span>:<span style="color: #000000;">45</span><span style="color: #000000;">}</span><span style="color: #000000;">)</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #666666;">// set multiple properties of an Object</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">function</span> setProps<span style="color: #000000;">(</span>o:<span style="color: #0033ff;">*</span>, props:<span style="color: #0033ff;">Object</span><span style="color: #000000;">)</span>:<span style="color: #0033ff;">void</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #0033ff;">for</span> <span style="color: #000000;">(</span><span style="color: #0033ff;">var</span> key:<span style="color: #0033ff;">String</span> <span style="color: #0033ff;">in</span> props<span style="color: #000000;">)</span> <span style="color: #000000;">{</span></div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;">o<span style="color: #000000;">[</span>key<span style="color: #000000;">]</span> = props<span style="color: #000000;">[</span>key<span style="color: #000000;">]</span>;</div>
<div style="font-family: 'Courier New',Courier,monospace; font-weight: normal; color: #000000;"><span style="color: #000000;">}</span></div>
<p><span style="color: #000000;">}</span></div>
</div>
</div>
<p>This snippet allows us to set the properties of any <span>Object</span> using a function call and <span>Object</span> syntax. This technique is commonly used within tweening engines such as <a href="http://blog.greensock.com/tweenliteas3/" target="blank">TweenLite</a>.</p>
<p>Take a look at line 7. Here we call the <span>setProps()</span> function. The first argument is the <span>Object</span> (a <span>Sprite</span>, in this case) that we want to change and the next argument is an <span>Object</span> that contains new values for the properties of the object you passed into the first parameter. Line 7 alters our sprite&#8217;s <span>x, y, scaleX, scaleY</span> and <span>rotation</span> properties all with one function call.</p>
<p>The <span>setProps()</span> function itself makes use of two interesting ActionScript features, the <span>for&#8230;in</span> loop and <span>Object</span> bracket syntax. Bracket syntax can be very powerful. It&#8217;s an alternative to dot syntax, instead of writing:</p>
<pre>mc.x = 10;
mc.y = 10;
mc.rotation = 45;

// bracket syntax allows us to write:

mc["x"] = 10;
mc["y"] = 10;
mc["rotation"] = 10;</pre>
<p>The reason this is useful is that you can use a variable between in your brackets and change which property or method you&#8217;re targeting.</p>
<p>On line 11 we make use of the <span>for&#8230;in</span> loop. This allows us to loop through the properties in a given <span>Object</span> (stored in <span>props</span>, in this case). Notice the <span>key</span> variable inside our <span>for&#8230;in</span> loop. This variable is set to the name of each property in our <span>props</span> <span>Object</span>. To understand this a bit better you could try adding a trace statement inside the <span>for&#8230;in</span> loop:</p>
<pre>for (var key:String in props){
    trace(key);
}</pre>
<p>outputs:</p>
<pre>scaleY
y
x
rotation
scaleX</pre>
<p>This means that line 12 is setting the properties of our first argument equal to the properties of our second argument. If we unrolled the loop it would look like this:</p>
<pre>o["scaleY"] = props["scaleY"];
o["x"] = props["x"];
o["y"] = props["y"];
// etc</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=13dV0BRIzJs:fyp2IphuTAE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=13dV0BRIzJs:fyp2IphuTAE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=13dV0BRIzJs:fyp2IphuTAE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=13dV0BRIzJs:fyp2IphuTAE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=13dV0BRIzJs:fyp2IphuTAE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=13dV0BRIzJs:fyp2IphuTAE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/flashbanneronlineblog?a=13dV0BRIzJs:fyp2IphuTAE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/flashbanneronlineblog?i=13dV0BRIzJs:fyp2IphuTAE:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/flashbanneronlineblog/~4/13dV0BRIzJs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2009/10/tricks-and-experiments-as3-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.flashbanneronline.com/2009/10/tricks-and-experiments-as3-tips/</feedburner:origLink></item>
	</channel>
</rss>
