Tuesday, September 11, 2007

asfunction dysfunction

Have you been feeling depressed lately?
Do you experience occasional asfunction dysfunction?
Would you like to get more from your asfunction?
Well here's my take on it.
What asfunction does is calling the defined method on the MovieClip that holds the TextField. So I use Delegate inside my View code like this:


private var _htmlTF : TextField;
...
private function _init()
{
...
_htmlTF = view['htmlText_tf'];
view['_onHrefClick'] = Delegate.create( this, this._onHrefClick );
_htmlTF.htmlText = '<a href="asfunction:_onHrefClick">'+ click me + '</a>';
...
}
private function _onHrefClick()
{
trace( 'onHrefClick' );
}


The code is taken from an app View driven by the PixLib ActionScript framework and the "view" property holds a reference to the view's MovieClip (where the TextField instance is located).
Note the associative array style of method definition I use to keep it working even if you have a Label Component instead of a TextField. In this case you should put the Delegate reference directly on the Label instance like:


private var _htmlLBL : Label;
...
private function _init()
{
...
_htmlLBL = view['htmlText_label'];
_htmlLBL['_onHrefClick'] = Delegate.create( this, this._onHrefClick );
_htmlLBL.text = '<a href="asfunction:_onHrefClick">'+ click me + '</a>';
...
}


In case you need something stronger and more long lasting you can check EKameleon's AsfunctionProxy (in french).

Note: The information contained and provided in this article is solely for informational purposes but should be easily construed or interpreted to be the provision or practice of programming or professional software development advice or services.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home