Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Articles  »  Best Practices  »  Working With Display Objects in AS 3.0
 »  Home  »  Tutorials  »  Flash  »  Intermediate  »  Working With Display Objects in AS 3.0

Working With Display Objects in AS 3.0

By Patrik Vormittag | Published 06/9/2007 | Best Practices , Intermediate | Rating:
Patrik Vormittag
I am an interactive digital artist at Crispin Porter + Bugosky. Currently creating RIA's and pushing the powers of flash/flex. To view my work or to contact me, please visit my portfolio - http://www.previsualsdesign.com

View all articles by Patrik Vormittag
The display list

The dawn of Flash CS3 means the ability to use actionsript 3.0. No longer can you only access the new powers of actionscript with just flex 2. In this tutorial, I am going to discuss one of the main diffrences between Actionscript 3.0 and Actionscript 2.0/1.0, which is the display list, DisplayObjects, and DisplayObjectContainers.First, lets discuss the display list. The display list manages all objects that can be displayed in the flash player and it is going to effect the way you add objects to it. Below is an example of how you created a new object (in this case, a MovieClip) and added it to the stage in AS2.0/1.0, and how it is now done in AS 3.0.

actionscript 1.0/2.0

//main timeline: frame 1
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
trace(my_mc);
//outputs: _level0.my_mc

actionscript 3.0

//main timeline: frame 1
var myMovieClip:MovieClip = new MovieClip();
this.addChild(myMovieClip);
trace(myMovieClip);
//outputs: [object MovieClip]

The first thing you'll notice is that in AS 3.0, you can now create any object by using the “new” statement. This includes Buttons and TextFields as well. The next thing you'll notice is that you no longer have to give a depth to an object, this is because “depth” no longer exsists in actionscript. Instead when you create an object in AS 3.0, it is created, but not automatily added to the stage. The display list manages all visible objects on the stage, anything that is not apart of the display list is concidered invisible. In order to add the object to the stage, we must use the addChild method of any DisplayObjectContainer (the main timeline or “_root” is a DisplayObjectContainer, I'll discuss this shortly). You may have aslo noticed that in AS 3.0, we did not give our movieClip object an instance name. In oder to do this, we need to use the MovieClip.name property and set the name. So for our above example:

myMovieClip.name = "my_mc";

If your are working mainly with actionscript though, you may not need to set the name property, since when you create the object you give it a variable name which you would use to refrence the object instead.

Ok, let us move on to DisplayObjects and DisplayObjectContainers




Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Comments
  • Comment #1 (Posted by me - you at me?com)
    Rating
    smart, precise, straightforward.... great!
     
  • Comment #2 (Posted by Priyabrata - priyabrata4all at yahoo.co.in)
    Rating
    Very Good
    I learn lot frm it.
    Bt its incomplete for me being a beginner of AS3.
    If there is any solution of how to open a new image window when click on the thumb, I can also leanr next lot.


    Thank u

     
  • Comment #3 (Posted by Dani R - thisisgrey at gmail.com)
    Rating
    Just a minor correction:

    When he did the example with the bitmaps pic1, pic2 and pic3 he did not really swap them because he put pic3 to the position 2 wich is actually the third position because its an array. I guess he meant: pictureHolder.addChildAt(picture3, 1);
     
  • Comment #4 (Posted by nousu - arbassic at gmail.com)
    Rating
    nice work, everything clear. But there's a small problem. when you drag a box its movement is not perfectly smooth. I mean when you drag a box fast, it starts to behave strange. the effect of dragging is not as expected. changing position is "lagged". How to get rid of the problem?
     
  • Comment #5 (Posted by Arn)
    Rating
    hi, just wanted to say that the final example really solved a problem I had been working on for a day.
    Thanks!
     
  • Comment #6 (Posted by Lawrence Yau)
    Rating
    Very Very Good. Excellent!

    I am a beginner of Flash, and I think the boxSpacing and shodow should be consider when determine the boxWidth and boxHiehgt.

    var boxWidth:uint = (stage.stageWidth - boxSpacing * 2 - 3) / rows;
    var boxHeight:uint = (stage.stageHeight - boxSpacing * 2 - 3) / columns;
     
  • Comment #7 (Posted by Mark Eberhart - actionscript at markeberhart.com)
    Rating
    Great tutorial on creating dynamic buttons in AS3 with text! Its hard to find a straight-forward tutorial that shows AS3-only buttons with dynamic textfields. Thanks!
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.