Ultrashock Tutorials > Flash MX 2004 > Introduction to the v2 component architecture  
 
by Chafic Kazoun, Rewindlife.com
Download PDF file 
 
Introduction to the v2 component architecture
 

01. Introduction
02. Setup and Core Implementation 
03. Public API
04. Utility methods

05. Events
06. Additions to the Public API
07. Conclusion

- discuss this tutorial -

III. Utility Methods

Utility methods are available for you by the component architecture so as to make your life easier during certain tasks. If you have used these methods before, you may skim through them quickly.

cancelAllDoLaters()

cancelAllDoLaters() deletes the array of queued function calls, thus causing all doLater() calls to be wiped out. Check out the information on the doLater() method for further detail.

doLater(obj:Object,function:String)

The doLater() method is a handy way of postponing a method call to the nextframe. When calling this method and passing the required parameters, the function will store a reference to the method in an array and call it in a future frame. If multiple calls are made, they are all executed in the next frame. Keep in mind that when a component is invalidating, the methods in the array will all be called automatically. However, when you call an immediate redraw(), the methods will be called immediately. Instead, they will be called a frame afterwards. This is very handy if you have had to use onEnterFrame before to postpone a method call. Example: doLater(this,”setSomething”) will cause the setSomething() method of “this” object to be called in a the next frame;

createLabel(name:String, depth:Number, text:String)

This will create a TextField that listens to its styling value’s by default from the class that created it. This is the recommended way of creating labels.

getTextExtent2(text:String)

A better implementation of getTextExtent() that is added to the TextFormat class’s prototype at runtime. The usage is the same as the original getTextExtent().

drawRect(x1:Number, y1:Number, x2:Number, y2:Number)

Will allow you to draw a rectangle easily by passing in the value’s of the 4 points.

setSkin()

This is used for when you implement skinning functionality for your component. We will not be discussing the details of the skinning architecture in this article.

getStyle(styleProp:String)

The getStyle() method will return the value for a specific style. Example: getStyle(“color”), would return the value of the color style as set by the user. If you have used the styling features for components before, you probably saw the ability to set styles globally, on a per instance basis, and per class. The getStyle() method takes care of returning the appropriate value as set on any of those locations. If you have not implemented the skinning functionality which usually includes the default value’s for a components style, you will receive an undefined value if the style has not been set by the user. You should check for this condition accordingly when calling the getStyle() method an handle it appropriately.

setStyle(styleProp:String, value)

If you have used components and have attempted to customize their look/feel, you probably ran into the setStyle() function. This function is added to our component to allow a user to set the value of a style on a per instance basis.

- discuss this tutorial -
 
©2004 Ultrashock.com - All rights reserved