Here's a little hack a use when I'm using when I need to an event handler to access variables or object in a particular function scope.
import flash.events.MouseEvent;

var clickHandler : Function;

function foo() : void
{
        var firstName : String = "Samuel"
        var lastName : String = "Agesilas";
        
        this.stage.addEventListener(MouseEvent.CLICK, clickHandler = function(event:Event) : void
        {
                trace( event );
                trace( "First Name:" + firstName );
                trace( "Last Name:" + lastName );
        });
}
foo();
By creating a variable ('clickHandler') outside of the current function scope (in this case the function 'foo') we have a safe place to store the function handler and it can be removed at a later point in time if necessary. The biggest advantage here is that now the 'clickHandler' has access to all of the variables and objects inside of my current function scope making event handling a lot easier and with less code.

cheers!
Sam

Subscribe to Planet Flash

Search

Tags

<head> 3d 3d Flash Actionscript actionscript 3 ActionScript 3.0 Adobe Adobe Air Adobe AIR (Apollo) Adobe Flash Adobe Flex AdobeMAX08 AIR AIR Adobe Integrated Runtime Announcements apollo Art as3 Asides awards Babble BEA Beautiful Web Books Business Cairngorm ColdFusion Community Components Conference Conferences design dev Development Events Examples Featured Flash Flash CS3 Flash experiments flash player Flex Flex 3 Flex Builder Flex Builder Development Flex Example FMS Fun Gallery General GeoWeb Google Industry Inspiration Jobs linux Marketing MAX MAX 2007 Misc News news & events Off topic Open Source Other Papervision3D Personal photos Photoshop Process Processing RIA Singularity Site News Stuff techmology Technology Tennis Thinking Loud Tips Uncategorized Video Whatever

Blogs

Buttons

Planetarium