t-roy.net*
blog by designer troy ginbey
Archive for May, 2008
May 25, 2008 at 12:21 pm · Filed under AS3.0 Fundamentals, Adobe Flash
Wow… every so often you stumble upon something that you know will change the way you design forever. I was flicking through the ACP (Adobe Certified Professional) Exam Guide for Flash CS3 (as you do on a Sunday), and came across something I didn’t recognise - scale9Grid.
scale9Grid divides a display object into 9 regions, allowing different rules to be applied to it when the object is scaled.
How is this useful?? Well.. think about designing a simple content area with rounded corners. You want the content area scale vertically as the amount of text it holds increases. With any normal object with rounded corners, as you scale it’s height, the corners would scale and distort the more it is verticaly scaled. Enter scale9Grid. With one line of code, you can define the regions of the rounded rectangle to allow for distortion free scaling… Here’s an example:
myRoundedRectangle.scale9Grid = new Rectangle(10,10,300,600);
The above code adds a scale9Grid to a rounded rectangle object - meaning when it is scaled, the rounded corners will stay the same…. Brilliant!
May 22, 2008 at 10:30 am · Filed under AS3.0 Fundamentals, Adobe Flash
I’ve been using Array for a while now - but don’t frequently use all of it’s methods… so I’m going to go through the ones I don’t use a lot….
Array.sort();
var beers:Array = ["Fosters", "Alpha", "VB", "Asahi"];
beers.sort(); // default sort
trace(beers); // output: Angelou,Blake,Dante,cummings
beers.sort(Array.CASEINSENSITIVE);
trace(beers); // output: Alpha,asahi,Fosters,VB
beers.sort(Array.DESCENDING);
trace(beers); // output: asahi,VB,Fosters,Alpha
beers.sort(Array.DESCENDING | Array.CASEINSENSITIVE);
trace(beers); // output: VB,Fosters,asahi,Alpha
May 21, 2008 at 3:33 pm · Filed under AS3.0 Fundamentals, Adobe Flash
package {
import flash.display.*;
import flash.text.TextField;
public class AS3Tester extends Sprite {
public function AS3Tester() {
var myTextContainer:TextField = new TextField();
myTextContainer.text = "I like beer";
this.addChild(myTextContainer);
}
}
}
In the above code, I create a variable to reference a new TextField object, and set it’s text to “I like beer”. This alone wont add the TextField to the stage. To do this I then need to use the addChild method to add it to the display list:
addChild(child:DisplayObject):DisplayObject
addChild is a method of DisplayObjectContainer. When a DisplayObjectContainer (a Sprite, a Loader or the Stage) calls the addChild method, it adds a child DisplayObject instance to that DisplayObjectContainer instance.
To remove an object from the display list is the reverse:
removeChild(child:DisplayObject):DisplayObject
So the code to remove the TexField above would be:
this.removeChild(myTextContainer);
If I wanted to add a display object instance to a specific DisplayObjectContainer instance, I use addChildAt:
addChildAt(child:DisplayObject, index:int):DisplayObject
Here’s an example of the code in use:
var myDisplayContainer:Sprite = new Sprite();
var myFirstSprite:Sprite = new Sprite();
var mySecondSprite:Sprite = new Sprite();
myDisplayContainer.addChild(myFirstSprite);
myDisplayContainer.addChildAt(mySecondSprite, 0);
this.addChild(myDisplayContainer);
The above code first creates a DisplayObjectContainer called myDisplayContainer, then adds a Sprite (myFirstSprite) to it. Then using addChildAt, a second sprite is added to myDisplayContainer at index 0, which is the back of the list - meaning it will be displayed underneath myFirstSprite.
The final line adds the myDisplayContainer to the stage.
May 20, 2008 at 9:43 am · Filed under AS3.0 Fundamentals, Adobe Flash
Display List programming is a big part of ActionScript 3.0… Basically anything that is visually added to the stage must be added to Flash’s Display List hierarchy.
In the next few posts I’m going to go through a few core display programming tasks…
- Adding display objects to the display list
- Removing objects from the display list
- Moving objects among display containers
- Moving objects in front of or behind other objects
May 18, 2008 at 7:01 pm · Filed under AS3.0 Fundamentals
An XMLList is a great object for working with one or more XML elements. You can call methods on the elements as a group or on the individual elements in the collection. In the example below, I’ve created an XML List to store all beers from the beers XML object that have the brand “fosters”:
beers:XML = XML;
showBeersByBrand("alpha");
private function showBeersByBrand(name:String):void {
var results:XMLList = beers.beer.(@brand == name);
showList(results);
}
private function showList(list:XMLList):void {
var item:XML;
for each(item in list) {
trace("item: " + item.toXMLString());
}
}
May 18, 2008 at 4:50 pm · Filed under AS3.0 Fundamentals
For each in is a handy statement to iterate over items in a collection (or object), and execute statements on those items - for example, an Object, Array, or XML. I’ll give an example of each of these…
Object
var myObject:Object = {name:"Shofferhoffer", type:"Wheat Beer", alcoholPercentage:4.5, origin:"Germany"}
for each (var item in myObject) {
trace(item);
}
outputs:
4.5
Germany
Shofferhoffer
Wheat Beer
Array
var myArray:Array = new Array("Corona", "Shofferhoffer", "Fosters");
for each (var item in myArray) {
trace(item);
}
outputs:
Corona
Shofferhoffer
Fosters
XML
var myXML:XML = merlotshirazwheat beeralelager;
for each (var item in myXML.beer) {
trace(item);
}
outputs:
wheat beer
ale
lager
The for each..in statement iterates only through the dynamic properties of an object, not the fixed properties. And unlike the for..in statement, the for each..in statement iterates over the values of an object’s properties, rather than the property names.
So, there’s a few good usage examples for for.. each.. in. Worth keeping in mind when working with objects!
May 18, 2008 at 4:29 pm · Filed under AS3.0 Fundamentals
I’ve decided I’m going to start writing on a few AS3.0 coding basics - from simple for statements, to the XML Class, XML List, Array Class etc.
I’ll be posting these in a new “AS3.0 Fundamentals” category, but you’ll also find them under the Adobe Flash section.
May 18, 2008 at 10:50 am · Filed under Adobe Flash
Flash Player 10 is in beta - going by the name “Astro”. New features of the player include 3D Effects which allow you to use APIs to animate objects through 3d space, lightweight runtime Custom Filters & Effects (which use the same technology as some After Effects CS3 filters), a new advenced Text Layout system which co-exists with TextField, an enhanced Drawing API with 3D APIs, shape drawing systems and re-stylable properties. Visual processing is also shifted more to the video card, which should allow smoother video.