Difference between revisions of "Actionscript 3 Sandbox"

From Wikicliki
Jump to: navigation, search
(Basics of AS3)
(Basics of AS3)
Line 51: Line 51:
 
return thing1_mc.y;
 
return thing1_mc.y;
 
}
 
}
border2_mc.y = moveObj();</pre>
+
thing2_mc.y = moveObj();</pre>
  
 
* events must have listeners
 
* events must have listeners

Revision as of 11:07, 5 July 2009

AS3 brings the core language aspects of AS2 into complianace with ECMAScript standard (the international standardized programming language for scripting).

Basics of AS3

OPTION F9 == Actions Panel

  • The difference between AS2 and AS3:
AS2:
my_MC.createTextField("instance_name", 10,0,0 Stage.width, 22);
my_MC.attachMovie("MC_name", "moviename_mc, this.getNextHighestDepth());
10,0,0,Stage.width == dimensions
22 == depth

Versus AS3:
var myText:TextField = new TextField();
var myMC:MovieClip = new MovieClip();
now in AS3 you dont have to createTextField or attachMovie, and you can define all the variables later. 
  • select the property (highlighted in blue in the Actions panel), and press F1 to see a help menu telling you about what values the property can have.
  • strings must be in quotation marks (var userName:<DataType> = "Data";)
  • you assign data type to the variable so you dont lose track of what it is.
  • trace(variableName);
  • trace("long text comment");
  • function thing():void - the void means no return argument
function moveObj(thing:MovieClip):void 
{ 
thing.y -= 50;           			// mc moves 50px up
thing.rotation += 45;		// mc rotates 45 degrees right
}
moveObj(thing1_mc);
function moveObj(thing:MovieClip, movement:Number, rotationAmount:Number):void 
{
thing.y -= movement;           			// mc moves 50px up
thing.rotation += rotationAmount;		// mc rotates 45 degrees right
}
moveObj(thing1_mc, 50, 45);
function moveObj():Number		// the number here defines what kind of thing is returned
{ 
thing1_mc.y -= 50;
thing1_mc.scaleY = 2;
return thing1_mc.y;
}
thing2_mc.y = moveObj();
  • events must have listeners