Archive for the ‘Adobe AIR’ Category

* vs. Object in ActionScript 3

March 22, 2011

ActionScript 3 doesn’t support Generics like some other languages such as Java. In the case you need to return a Generic type, e.g., your client code is expecting certain type, but the code that provides the service doesn’t know what type it is going to be, you simply use star (*), as opposed to Object:


public function createWindowInstance(type:Class,
allowMultipleInstances:Boolean = false):*
{
...
var windowToOpen:*;
windowToOpen = new ClassFactory(type).newInstance();
spark.components.Window(windowToOpen).open();
return windowToOpen;
}

Access main window application (top-level application) in Flex 4/AIR 1.5

March 6, 2011

Sometimes you need to access the top-level/main application (in terms of AIR desktop, it would be the main window, a.k.a the s:WindowedApplication instance that you set as “Default Application” under the default package) directly from your object. The reason for this could be that you have some sort of window manager that you roll out by your own that resides in the “default application” which manages all the windows in your application. You can communicate with the window manager via some event mechanism, or simply directly send a message to it from within your window object, like this:

FlexGlobals.topLevelApplication.windowManager.closeWindow(this);

FlexGlobals and topLevelApplication work on Flex 4, AIR 1.5 and Flash Player 10.

Uninstall Adobe AIR application in Linux/Ubuntu

September 11, 2009

I am talking about AIR 1.5.2 installer and Ubuntu 9.04 (cat /etc/lsb-release to find out your Ubuntu version).

Simple run the installation package file (*.air, which is basically an zip file) again. If you don’t know where it is (and presumably still in your machine), go to “Applications->Accessories->Adobe AIR Application Installer”, which opens the most recently installed AIR package (*.air), then click “Uninstall”.

Tracking mouse movement in Flash Player

June 8, 2009

In a recent prototyping project, I attempted to simulate “shake” gestures in a desktop AIR application, i.e., using mouse cursor to simulate a hand grabbing some object on the screen…

Anyhow. I found out that Flash Player can send out the mouseMove event must faster than it can update the screen. In the case you want to keep track of the simulated gestural motion, you would want to track the mouse cursor position on the stage, instead of the display object the mouse cursor is dragging. This is because when you drag the object to the point Flash Player cannot keep up with, the redaw will then not necessarily reflect the real positional changes of it in between the frames.

Take a look here. Right click to for the code. Also note that when directly register Application.application as the currentTarget we seem to get smoother tracking than if we registered the display object, like so:

mButton.addEventListener(MouseEvent.MOUSE_MOVE, mButton_handleMouseMove);/** you got more stripped out points than if you do this:

addEventListener(MouseEvent.MOUSE_MOVE, mButton_handleMouseMove);// this is btter.*/

MVC revisit: Take two

June 7, 2009

I find that MVC is much easier to understand both at the conceptual level and at the implementation level if you think about it from the perspective of how you communicate with the Model.

  1. Control is the input to Model. Basically, the Control is responsible to take input from the user or the system and stransfer it to the changes in the Model; The View is merely there to render the changes from the Model; so it can be considered as the output from the Model. You should keep the business logic as much as possible inside the Model and leave Control/View simple and dandy.For Flex 3 (Halo) components, the way of input is realized by implimenting the “change” listener of the controls, like this:

    <mx:TextInput id="mTxt" change="mVO.txtValue = mTxt.htmlText;"/>

    In Flex 3, when you bind a model to a control, it is one-way communication, meaning the control will reflect the change whenever there is one in the model; but the control would not be able to change the model. That’s why we need to wire through the change listener to make this happen.

    The output is hooked up by setter methods in the Model. Whenever you detect some changes that are historical, you would notify your listeners.

    [Bindable]
    public function set myValue(v:int):void
    {
    _
    myValue = v;
    notifyListeners();
    }

    In ActionScript 3, we normally implement “notifyListeners” by way of dispatchEvent. Your client listens to the event and updates the View by querying the changes from the Model. You may want to have different types of events so that your listeners can respond differently. For example, you normally would invalidate properties of your component and regenerate all the renderers when the data provider has changed, besides doing other updates; and you don’t want to do this kind of heavy-lifting each time when changes occur on the “less important” members of the Model.

  2. Asynchronous data. Sometimes you may compose something like an HTTPService component into your Model so that it can request external data.The data that are requested by the Control at a lot of times are not immediately available, and normally you would not notify your listeners until they are ready (For example, parsed into an XMLList object that can be consumed by component’s dataProvider).
  3. Static members are available before non-static members of the objects. You can use static members to set some initial values of your member variables.
  4. When you smell spaghetti code in your Model, try to partition/refactor your Model into smaller Value Objects. Value objects are a good way to structure your data/make flat Model hierarchical.
  5. For larger projects, you may want to duplicate Model (or value objects) so that multiple client can access the same data. For example, in your main window of your AIR application, you initialize your model like so:

    public var chatModel:ChatModel = new ChatModel();In another console window, you want to access the same model, like so:

    private var chatModel:ChatModel = Application.application.chatModel;

Change Adobe AIR window size dynamically

May 28, 2009

This changes your AIR app (main app’s window) to 100 px by 100 px.

Application.application.width = 100;
Application.application.height = 100;

scoping in flex/AIR components

April 1, 2009

Here.

“Effects in response to user input”

March 18, 2009

From” Joy of Flex“, buzzword UI/eye candy guru David Coletta.

Targetting Flash Player 10 on Flex development

December 20, 2008

Here: Targeting Flash Player 10 (UPDATED for FB 3.0.2)

One thing to remember is to “Do whatever you need to do in your OS to ensure SWF files are default opened by the new Flash Player 10 debug app”.

I didn’t realize that my system (Windows XP SP 3, with Flash CS3 and Flex Builder 3.0.1/2+sdk 3.2/4.0 installed) continued to associate FP 9 with .swf type even after I had had FP 10 installed (debug and non-debug); I was quite confused though whether it happened at the OS level (for all apps) or  only for Flex Builder. Anyhow during the compiling process, FB kept on complaining and all the complaints seemed to associate with the Player verison issue. Even confusingly the compiler or the runtime said it couldn’t write UIComponent.rotationX property, which seemed to signal that the SWF was running inside version 9, while a trace for “flash.system.Capabilities.version” did get “WIN 10,0,12,36”!

Long frustrations short, the following are a couple of ways I found worked for me:

1. Exploerer > “Tools” > “Folder Options” > “File Types” > Scroll down the “Registered File Types List” and choose “SWF Flash movie” > Choose “Advanced” button on the bottom > “Edit” > Substitute the path in the “Application used to perform action” to the path to FP10 in your system. This way FP10 shows up on top of FP9 in the “Recommended Programs” list!.

1. Uninstall/Reinstall Flash Player 10 that are downloaded from Adobe site. Restart.

2. (Bullet-proof) Add “-target-player=10.0.0” to the “Additional compiler arguments” before compiling.

FB stops hinting Flash Player 10 functions?

1. Make sure you are using playerglobal.swc from an SDK that targets FP10, which means SDK should be v3.0.1+(?) and it should reside in something like “frameworks/libs/player/10/playerglobal.swc”;

2. “Source attachement” option for the playerglobal.swc is “None” and the “Link type” should be “External”. Here.

Here are some links about code hinting in FB (SDK 3 vs. 4?) and the new Vector class (typed Array):

Kirupa forum: Using vectors (typed arrays) with Flex 3?

Mike Chambers: Using Vectors in ActionScript 3 and Flash Player 10

Access stage instance in Flex/AIR/Flash

December 17, 2008

In Adobe AIR:

If you want to access stage instance from the start-up of your application (usually to do some set-up stuff), you could access it with the “windowComplete” event for the WindowApplication tag (equivalent of “applicationComplete” for Application tag for Flash Player application), like so:

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml&#8221;

windowComplete=”initApp()”>

….

private function initApp():void
{
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
this.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}

In Flex (targetting Flash Player):

I believe you could do so within a “applicationComplete” handler.

In Flash:

Stage Access/Outside In