FlashSim Blog

Product simulations, Flash, state machines, and observations

Latest AS3 state engine on new area in Google Code

I’ve been plugging away on my AS3 state engine, and with a side-trip through repo-learning land, I think  I finally am at a point I can return to the work that I get paid for :-) !.

In any event, I messed up a Google Code project in my Git experiment, so the new home for the AS3 state engine is http://code.google.com/p/flash-state-engine.  I created a simple example to demonstrate it, a digital watch.  I will add more examples as time goes on.  Thanks to Zjnue Brzavi for his help in combing through the code to reveal bugs that demonstrate I shouldn’t be coding/developing too late at night.  He is developing a haXe port, though as I re-implemented the engine in AS3, I also have been mucking around with the API–sorry, Zjnue!

August 17, 2009 Posted by jonkaye | AS 3.0, Google Code, State Machines | | No Comments Yet

Packaging my Hierarchical State Machine implementation for AS 3.0

It has been a long time in coming, but I am finally getting ready to release our alpha version of our hierarchical state machine for Flash ActionScript 3.0!

I will be writing blog entries over the next few weeks as I document my path to release.  It hasn’t been hard to organize things, but I’ve certainly benefitted from finding blog posts about installing or doing this or that.

To begin the process, I created a Google Code project here.  I had to choose a version control system for the code, so I chose Git.  I was using Tortoise SVN for other projects, but I have heard good things about Git, and the idea of allowing others to fork projects without creating a whole new project was really intriguing to me.  I have only had mild encounters with Flex, but I certainly believe that one of the great values in making a state machine implementation is going to be integrating the engine into Flex.  However, I’m not the guy to do it well.  Therefore, I’m trying to appeal to others who are more familiar to create a Flex fork, perhaps, or maybe haXe, and allow these other projects to influence where I might go with the AS3 implementation.  The wonderful thing about not understanding all of this is that I am not limited to what the things actually do, only what I believe they should do :-) !

I have been developing the AS3 code in FlashDevelop, which is wonderful (needless to say).  While of course I have Flash CS4, on my kick-ass iCore 7 Vista machine, the ActionScript editor inside Flash becomes painfully slow with only 1 or 2 pages of code, especially when I start typing things inside quotation marks.  I’m now cleaning up the comments and generating the documentation via ASDoc.  FlashDevelop has a command to initiate ASDoc, you just have to provide a few key pieces of information.  For example, for AS 3, FlashDevelop requires you to specify where asdoc.exe resides.  I have Flex Builder and the Flex SDK, so it was simple to navigate over to the sdk/ folder, find the latest version (3.3), and point to it inside the bin/ folder.

The Adobe Flex docs are pretty good for helping to understand the tags for ASDoc.

August 8, 2009 Posted by jonkaye | AS 3.0, FlashDevelop, Git, Google Code, State Machines | | No Comments Yet

Dispatching custom event in handler for other event [AS3]

I’ve been struggling with an issue that I can’t seem to understand, but I found a workaround so I have to move on.  Maybe someone out there will have a better grasp of what is going on.

In my event handler for a Timer object, I dispatch a custom event, but not the event that came into the handler.  To try to save some space, since my custom event could be called a lot of times, I keep a single copy of the event in my custom class.  Here is my Timer object event handler:

   private function timerElapsed (ev:Event) : void {
      dispatchEvent(pulseEvent);
   }

In the initialization of my class, I create the pulseEvent object:

   internal var pulseEvent:EventWithData;
   ...
   pulseEvent =  new EventWithData(PulseActivity.TICK, false, false, customData);

When I run the code, the pulseEvent is sent along fine the FIRST time.  The second and subsequent times, Flash sends a different event which does not have the custom data.

This led me to suspect something to do with clone(), judging from the AS3 documentation:

Returns a new Event object that is a copy of the original instance of the Event object. You do not normally call clone(); the EventDispatcher class calls it automatically when you redispatch an event—that is, when you call dispatchEvent(event) from a handler that is handling event.

The new Event object includes all the properties of the original.

When creating your own custom Event class, you must override the inherited Event.clone() method in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when listeners handle the redispatched event.

The odd part in this is that I’m not redispatching the event coming in — I’m dispatching a different event (the one I’ve created and stored in the custom class).  I suspect somehow my new event dispatch is getting caught up in this and Flash is cloning the event, but since I didn’t create an override (lazy me) for clone, I’m paying the price.

Rather than going this route, I realized I don’t really need my custom Event class, rather, I can use Event and use the target property (ev.target) to get to the object dispatching the event, then make a property off that class to store the custom info I want (Whew!).  I am a bit unsettled with all the potential cloning going on, but I am under a deadline so I will have to revisit it in the future (which could be way in the future).  I hate these kinds of loose ends!

[8/6/09 Update, 14:20.  Yes, it turned out to be the clone issue.  When I correctly added a clone override, the original code worked.  I think this means that the space I'm trying to save is not working because clone gets invoked to create a new event.  Oh, well, can't say I didn't try.  If I see a problem regarding the load, maybe I will try to address it again in the future]

August 6, 2009 Posted by jonkaye | AS 3.0 | | No Comments Yet

Update…Getting Close to Clearing My Schedule

It’s been a hectic past few months as I’ve been working on small projects and not getting a chance to get my head above water.  It’s been hard to make progress on advancing technical work when there is so much business organization, marketing, and sales work to accomplish.

I’m almost at a point I can return to some technical work to get more of my libraries over to AS3.   I will be posting as I get deeper into this…

May 26, 2009 Posted by jonkaye | AS 3.0, Device Interface Components, State Machines | | No Comments Yet

Web Services in AS3 and Charts

I’ve been working on a user interface to our behavioral metrics system as an easy project to get more into AS3.  Our system uses web services to communicate with the back-end DB, so when I opened up CS4 I went looking for the WebService class.  Much to my surprise, I couldn’t find anything.

A few searches later, it appears that the WebService class from prior Flash versions is no more.  Very odd, kind of like the missing 3rd-party help in CS 4 (still can’t figure that one out — how could Adobe drop such a feature?).

Anyway, I came across this web service class library by Carlo Alducente, which is fabulous.  It saved me a lot of time and it was free.  Thank you so much, Carlo!

On the subject of plots and graphs, I found a great, basic set over at Yahoo, the Yahoo Flash Astra Components.  It has a set of bar, line, and pie charts which are easy to adapt and use.  Then there are a bunch of other components in the set, such as for canvas layout.

December 1, 2008 Posted by jonkaye | AS 3.0 | , | No Comments Yet

Where am I?

I am not so lost as my title suggests, but I ran into an issue as I get into AS 3 that doesn’t quite make sense to me yet.

I was setting up an event handler within the scope of a class definition, and using an anonymous function to handle the event:

title.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent) { ...

I expected that if I used ‘this’ inside the anonymous function, I would be able to reference the instance.  However, I get something different, some global variable (on trace, it comes out [object global]).  If I use ‘parent’ inside the anonymous function, I get the parent of the instance, but I can’t seem to get a pointer to the instance.

Of course  If I make my event handler as a method of the class, I get ‘this’ to refer to the current instance.  No time to dwell on this now as to why I get this behavior, but I thought it was interesting.

November 22, 2008 Posted by jonkaye | AS 3.0 | | No Comments Yet