Develop PHP Website for Learning Web Design Free Online
  Home   |   Forums   |   DevCMS
  Join   |   Log In
 
   

Actionscript 3.0 Tutorials - Learn Actionscript 3.0

Tutor at Develop PHP
Object Properties and Methods
By: Adam      Created: Jul 07, 2009      Views: 6542 Tweet This Page  Post page to Facebook  Post page to Facebook

Each object created through code or manually created and given instance name on stage in ActionScript 3.0, has certain properties and methods associated with it for the particular data type the object may happen to be.

Properties

Once an object is created and defined we can access certain characteristics known as properties of that object using Dot ( . ) syntax. The dot follows directly after the object's instance name and opens a doorway to the properties and methods of that object. To better convey the idea and functionality lets show a code example. Drag a rectangle out to stage, right click it, convert to movieclip symbol, then give it an instance name of "myBox".
Learn HTML
var boxW:int = myBox.width;
var boxH:int = myBox.height;
var boxX:int = myBox.x;
var boxY:int = myBox.y;
var boxV:Boolean = myBox.visible;

trace(boxW);
trace(boxH);
trace(boxX);
trace(boxY);
trace(boxV);

// move the box to top left corner using code
myBox.x = 0;
myBox.y = 0;


Develop PHP browser display window
201
136
162
70
true

As you can see you in the example above you have just accessed and more importantly, adjusted a few of the properties of that button object using its instance name. Here is another example of accessing the properties of a simple string variable.
Learn HTML
var carMaker:String = "TOYOTA";

var stringLength:Number = carMaker.length;
trace("String object has " + stringLength + " characters");


Develop PHP browser display window
String object has 6 characters

Methods

Methods are more like actions that can be performed by an object. When we create movieclips we can access their methods using the Dot ( . ) operator like we do for accessing properties. The data type determines what methods are associated and can be used on that object. To best demonstrate this to yourself create a movieclip with an instance name of "myClip". Make a timeline animation play over 20 frames with a low frame rate. Use the following code to make the animation stop on command by accessing those methods for the object. play() works as well.
Learn HTML
if (myClip.currentFrame == 10) {
    myClip.stop(); // will never make it past frame 10
}

In the example above we checked the movieclip's currentFrame property, and then used one of that data types methods( stop() ) to have actions apply to it that we want.

gotoAndPlay() and gotoAndStop() are methods that can be applied to timelines of movieclips as well.
                                   Conditional Statements


Comment on Object Properties and Methods




Search Tags:
Object   ·  Properties   ·  and   ·  Methods   ·  
 
 
Arbitrary Links and Archives
Home
Active Forums
Members
SIte News
Link To Us
Gear
2009 Forum Archive
Programming Courses
Learn HTML
Learn CSS
Learn PHP
Learn MySQL
Learn Javascript
Learn jQuery
Learn ActionScript 3.0
Learn Java
Learn XML
DevelopPHP Requires Flash Player
Get Adobe Flash player
___________________________________________

Terms of Use  •  Privacy  •  Admin Notes

©2010 developphp.com   |   Powered By FlashBuildingHolder