AS3 avatar notes: Difference between revisions

From Whirled Club Wiki
Jump to navigation Jump to search
(Created page with "{{Infobox tutorial |type=ActionScript |difficulty=Beginner |description=Create a smiple avatar using AS3. |requirements=20px [[ActionScript 3.0]...")
 
m (Text replacement - """ to """)
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
== How to add a state to the list of states ==
== How to add a state to the list of states ==


<actionscript>
<actionscript>
_control.addEventListener(ControlEvent.STATE_CHANGED,stateChanged);
_control.addEventListener(ControlEvent.STATE_CHANGED,stateChanged);
_control.registerStates([&quot;State1&quot;,&quot;State2&quot;,&quot;State3&quot;, &quot;...&quot;]);
_control.registerStates(["State1","State2","State3", "..."]);
&lt;/actionscript&gt;
</actionscript>


== How to add code to the state ==
== How to add code to the state ==


&lt;actionscript&gt;
<actionscript>
protected function stateChanged(event:ControlEvent):void
protected function stateChanged(event:ControlEvent):void
{
{
     if(_control.getState()==&quot;State1&quot;)
     if(_control.getState()=="State1")
         {
         {
         // Insert code here.
         // Insert code here.
         }
         }
     else if (_control.getState()==&quot;State2&quot;)
     else if (_control.getState()=="State2")
         {
         {
         // Insert code here.
         // Insert code here.
         }
         }


     else if (_control.getState()==&quot;State3&quot;)
     else if (_control.getState()=="State3")
         {
         {
         // Insert code here.
         // Insert code here.
Line 39: Line 39:
     else  
     else  
         {
         {
         throw new Error(&quot;State not found!&quot;);
         throw new Error("State not found!");
         }
         }
}
}
&lt;/actionscript&gt;
</actionscript>

Latest revision as of 22:51, 5 September 2018

ActionScript Tutorial
Create a smiple avatar using AS3.
Difficulty Level
Beginner
Requirements
Icon-Programming.png ActionScript 3.0, Whirled SDK
Other Information
Next tutorial: Advanced avatar (ActionScript tutorial)

(Back to create avatars main page)

Icon-highlighted-avatar.png

This tutorial helps those using AS3 to build an avatar for Whirled. If you are interested in a less code oriented method using the Flash CS3 check out Advanced avatar (Flash tutorial). In this tutorial, we will be looking at numerous notes on avatars.


How to add a state to the list of states

<actionscript> _control.addEventListener(ControlEvent.STATE_CHANGED,stateChanged); _control.registerStates(["State1","State2","State3", "..."]); </actionscript>

How to add code to the state

<actionscript> protected function stateChanged(event:ControlEvent):void {

   if(_control.getState()=="State1")
       {
       // Insert code here.
       }
   else if (_control.getState()=="State2")
       {
       // Insert code here.
       }
   else if (_control.getState()=="State3")
       {
       // Insert code here.
       }
   else 
       {
       throw new Error("State not found!");
       }

} </actionscript>