Difference between revisions of "Actionscript 3 Sandbox"
From Wikicliki
(→Basics of AS3) |
|||
| Line 54: | Line 54: | ||
* events must have listeners | * events must have listeners | ||
| + | <pre>myMC.addEventListener(type:String,function) | ||
| + | myMC.addEventLIstener(MouseEvent.CLICK, onClick);</pre> | ||
| + | we are looking for a MouseEvent.SpecificallytheClick and once we hear it a function "onClick" will run | ||
| + | |||
| + | <pre>function onClick(event:MouseEvent):void { | ||
| + | trace("its been clicked!!!"); | ||
| + | }</pre> | ||
Revision as of 01:08, 6 July 2009
AS3 brings the core language aspects of AS2 into complianace with ECMAScript standard (the international standardized programming language for scripting).
- http://www.flashandmath.com/
- http://www.learningactionscript3.com/2009/06/30/as3-tips-tricks-and-experiments/#more-61
- http://www.adobe.com/devnet/flash/quickstart/creating_class_as3/
- interesting collection of as3 classes
- http://www.bytearray.org/?page_id=82
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
myMC.addEventListener(type:String,function) myMC.addEventLIstener(MouseEvent.CLICK, onClick);
we are looking for a MouseEvent.SpecificallytheClick and once we hear it a function "onClick" will run
function onClick(event:MouseEvent):void {
trace("its been clicked!!!");
}