



Do you frequently use simple actionscript functions in more than one project. Perhaps you’ve got a function to do tracking, parse strings to dates, or return a random colour etc.
I’m sure most folk will have struggled to think of what project they last used a generic function ABC in as they could do with using it for project XYZ and would rather spend 30 mins searching for said function rather than rewrite it.
Well as explained below is a way to stop this from happening and hopefully save you a heap of time.
– Create a library project.
– add in your Utilty class to the library project.
– add the reference of the newly created SWC file to any project you intend to use it in.
You are now done, any time you update the code in the library project, those changes will be reflected in any project that references the SWC file automatically.




Today while coding I was creating some classes that required them to dispatch custom events. I know that this is a fairly common thing to do but sometimes it is these little things that can trip you up or take a while to find out how to do them.
So I thought that each time I come across something that is ‘simple’ (only simple after you know it!) that I’ll try to create a quick blog entry and take note of it. Each time I create a new ‘tip’ post I’ll link it to the previous/next tip so that it will be quick and easy to browse through a load of tips.
So for my first tip, this is how to implement your own custom events.
First if you are firing the events from a custom MXML file then you need to create a metadata tag. I make this the first node inside the MXML file. For example:
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="500" height="300" > <mx:Metadata> <!-- First two event are plain string events, they do not pass any specific data with them --> <!-- The last event is a custom class that extends Event and as such you need to give it its package name + the class name as the type --> [Event('next')] [Event('previous')] [Event(name='jump', type='com.kennethsutherland.events.JumpEvent')] </mx:Metadata> ...
If your custom class is an AS3 file then you would put something like the following are the imports
[Event(name="previous", type="flash.events.Event")] [Event(name='jump', type='com.kennethsutherland.events.JumpEvent')]
Then inside the MXML file (script block) or anywhere in the AS3 file to fire the event I’d do the following:
//custom event, the extra value is handled by the JumpEvent class dispatchEvent(new JumpEvent("jump", specificValueForTheJumpEventClass)); //standard event dispatchEvent(new Event("next"));
If you do the above and lets just say your MXML/AS file is called ‘GreatComponent’ then in order to use the new custom event, its as simple as the below bit of code.
<local:GreatComponent next="doSomething()" jump="doSomethingElse(event)" />
That’s it, now you can fire of any custom event that you wish and make sure that it gets listened to.
|
|


More Options ...
Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 