Difference between revisions of "Actionscript 3 Sandbox"

From Wikicliki
Jump to: navigation, search
Line 7: Line 7:
 
* http://www.bytearray.org/?page_id=82
 
* http://www.bytearray.org/?page_id=82
 
* http://www.flashandmath.com/advanced/card/math2.html
 
* http://www.flashandmath.com/advanced/card/math2.html
 +
 +
== problem solution ==
 +
 +
problem:
 +
mc.visible = 1 // WRONG, will generate error saying it is int where should be boolean
 +
 +
solution:
 +
mc.visible = true // CORRECT
  
 
== Basics of AS3 ==
 
== Basics of AS3 ==

Revision as of 15:24, 16 August 2010

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

problem solution

problem: mc.visible = 1 // WRONG, will generate error saying it is int where should be boolean

solution: mc.visible = true // CORRECT

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!!!");
}
  • myMC.buttonMode == use handcursor when its looking for event (eg: mouseevent)
function onClick(event:MouseEvent):void {
event.target.rotation += 45;
}     // this means that the thing which generates the event rotates!