Most people automatically think of AIR when they want to develop some cind of desktop application using Flash.
In my opinion Air isn't all that useful, it barely lets you do anything that your normal Flash player wouldn't let you do. I do not deny that it is useful in some cases, but if you want to do some stuff that are just a tad more interesting than your average code (for example reading and writing to Windows registry), it is not a very good choice.
So here's the path I took. At the company I work we develop Desktop applications using Flash. These applications need to be able to take user input while they are in full screen, need to read the path towards the the default application associated with a file type, etc.
So my first impulse was to use the flash player component (ActiveX) to make a self written projector witch can communicate with my swf files using FSCommand, FlashVars and FlashCalls, this actually worked, but we began having issues since the new FlashPlayer 10.
Since neither me or any of my coworkers did not find the solution for the problems we where experiencing, we decided that we should use some commercial products. We had a very large list of functions we needed from the projector, and very little(if any) space for compromise.
The first product we found was mdm Zinc, seemed to have everything we needed or an alternative path to get to the same places. We tried Zinc out, converted the source of the project we where working on to use Zinc instead of using our own projector. The conversion process was quite painful, and tedious, some functions worked as we needed them to, as they where described in the documentation of Zinc, other did't work as intended, or didn't work at all. Finlay after about 5 day, all our code was converted to use Zinc. Our product consisted out of aprox. 10 swf files, 1 swf file, loading the other 9 based on user interaction(only 1 at a time). We tested each file while we where converting it, but only tested the project as a whole after all the bits and pieces where ready. After being overwhelmed by the functionality offered by Zinc, we finally started testing our project as a whole, and it was a major disappointment, not only we found that our applications uses considerably more resources (thus making animations look horrible), we also found that it crashes randomly.
We then had 2 choices: 1. Find another product 2. Keep using our own projector.
After a little more searching we found Northcode SWF Studio, so hoping that this time we will have more luck we tried it out. The conversion of the source code was much faster, as all functions worked as intended, and we found the offline documentation to be more helpful, we also noticed a drastic decrease of resources relative to the same project made with Zinc.
I do not want to seem like a sales agent for Northcode, but i like to deal in facts: Air doesn't give you half of the functionality you need for a serous application, Zinc has serious stability issues, and thanks to Northcode SWF Studio our bugcount went down by aprox 60%.
Flash for desktop applications(Zinc VS AIR VS SWF Studio)
Tuesday, January 19, 2010 | Posted by DukeW at 8:10 AM 0 comments
Labels: Air, AS3, Flash, SWF Studios, Zinc
Using caurina Tweener
Some of you might be asking why use a third party tweening class when Flash has native code for it. The answers are:
- The native one has bugs. For example if you are simultaneously tweening 3 objects with native Tween class, from time to time you notice that one or more Tweens simply stop (at least this happened to me a lot while I was using the native class).
- You need 1 tween / tweened property. (If you move an object both on x and y you need two Tweens)
- It uses the same event model as everything in AS3(This is not necessarily bad, bit with Caurina Tweener you can not only specify the name of the handling function, you can also specify its parameters)
- Works fine regardless of the Tweened objects.
- Gives better performance.
- You can tween multiple properties of 1 object with a single line of code
- It's built with static functions, meaning that you don't need an instance of the class every time you want to make a tween.
The black box having instance name "box", and the initial alpha being 0.5 the code is:
import caurina.transitions.Tweener;
Tweener.addTween(box, {x:300, y:100, alpha:1, time:2, transition:"linear"});Animation sequences are also much easer to make, as you no longer need to synchronize your tweens using events, for example:
There are practically two tweens one that changes x,y and alpha, it lasts 2 seconds as you can see in the code above, and one that changes the rotation.
The code is:
import caurina.transitions.Tweener;
Tweener.addTween(box,{x:300, y:100, alpha:1, time:2, transition:"linear"});
Tweener.addTween(box,{rotation:50, time:1, transition:"linear",delay:2.5});No events no nothing just one extra parameter: "delay". As you can see it's set to 2.5, the length of the first tween is 2, so practicly the second tween starts 0.5 seconds after the first one finishes.
Still you may want to do something when your tween finishes playing, you accomplished this by 'addEventListener(Event.COMPLETE)' with tweener it's just another parameter as such:
Tweener.addTween(box, {rotation:50, time:1, transition:"linear",delay:2.5, onComplete:doThis});
function doThis()
{
trace("here");
} doThis will be called when tween has completed. As you can see doThis doesn't have any parameters, wich might be good, but in case you do need parameters, that is easy to acomplish as well:
Tweener.addTween(box,{rotation:50, time:1, transition:"linear",delay:2.5, onComplete:doThis, onCompleteParams:["hello world"]});
function doThis(s:String)
{
trace(s);
} NOTE: "hello world" can be replaced with a variable, or with multiple variables separated with comas. For example:
var nr1:Number=1;
var nr2:Number=2;
var nr3:Number=3;
Tweener.addTween(box,{rotation:50, time:1, transition:"linear",delay:2.5, onComplete:doThis,
onCompleteParams:[nr1,nr2,nr3]});
function doThis(n1:Number, n2:Number, n3:Number)
{
trace(n1+n2+n3);
}You can download examples from here.
You can read the online documentation for Tweener here.
You can download Tweener from here.
Hope somebody will find this usefull,
Best regards.
Friday, July 10, 2009 | Posted by DukeW at 8:18 AM 1 comments
Changeing text formating for individual cells of a DataGrid in Flash AS3
So lets start with the obviousness, create a new AS3 fla, and drag a DataGrid component to the stage. I will name it dataG.
Put this code on the frame:
import fl.data.DataProvider;
var xml:XML=<tickets>
<item>
<ID>231</ID>
<Status>Modified</Status>
</item>
<item>
<ID>232</ID>
<Status>Confirmed</Status>
</item>
<item>
<ID>233</ID>
<Status>Pending</Status>
</item>
</tickets>;
dataG.dataProvider= new DataProvider(xml)
If you publish the movie now, it should look something like this:
Tuesday, July 7, 2009 | Posted by DukeW at 8:01 AM 0 comments
Labels: CellRenderer, DataGrid, setter, TextFormat
Keyboard event not working
To begin lets consider the following case:
You are making a pac-man game, you want your user to have some control over the game so you place a menu button, you write the code for your menu. After you did this you notice that you no longer can control your pacman. After some headache you find out that if you click anything (except the menu button), your games works again. More technically speaking after doing removeChild to remove your menu your KeyboardEvent.KEY_DOWN/UP added to stage isn't firring any more. Example:
Just as described above you will see that the label at the top of the swf indicates correctly if a button is pressed or not UNTIL I remove the menu. Code is as follows:
var mainM:MovieClip;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyD);
stage.addEventListener(KeyboardEvent.KEY_UP,keyU);
btn.addEventListener(MouseEvent.CLICK,makeM);
function keyD(e:Event)
{
textField.text="Key pressed";
}
function keyU(e:Event)
{
textField.text="Key not pressed";
}
function makeM(e:Event)
{
if (mainM==null)
{
mainM=new menu();
addChild(mainM)
mainM.x=0;
mainM.y=60;
}
}
function destroyM(e:Event)//function called from mainM that tells the SWF that the menu needs to close.
{
removeChild(mainM)
mainM=null;
}
"menu" is in my library and has Export for ActionScript.So here's the part most people don't figure out (because its not really rational): though i did remove the menu from the stage, and eliminated any reference to it, since i clicked on the "Close Me" button it got focus, and it kept the focus even after being removed. (This is the irrational part... why would you want the focus on something that you cant interact with.). So let's recap, stage.addEventListener(KeyboardEvent.KEY_DOWN,example) is supposed to bubble to the stage, but the item that has focus, and there for is getting the event is no longer a child of the stage, this means the event will never bubble up back to the stage. The solution for this long and stupid problem is one tiny line:
stage.focus=anyMCOnStage;In my case all i have to do is to add this line:
stage.focus=stage;to my destroyM function. The result being:
Hope someone will find this helpful. Best regards.
Posted by DukeW at 2:27 AM 1 comments
Labels: FocusManager, KeyboardEvent, KeyboardEvent.KEY_DOWN, removeChild, stage