Progress Meters and performance

March 13th, 2008 AIR, Flex

I can’t say too very much about this but I do know for sure that in an AIR application I am working on we found that having an indeterminate status bar drove the CPU performance crazy. The interesting thing here is that I saw this with Vista, XP, and OS X. And, to top that, I found this when the progress meter was not even on the display list!

Let me explain that last part. I have it in a display stack and it’s not the selected item. So it’s in my MXML description, but not “drawn” as far as I understand it from a Flash perspective.

In any case, it’s a known bug for Adobe at this point. Note this will certainly get fixed, so check the date of this posting before you jump to the conclusion that this is your problem. In any case, see below for information on a bug report to Adobe on this item:

Deferred 1668388 [perf] Flex Progressbar set to indeterminite, the CPU usage is higher on MAC PPC (similar to bug 1657144)

This is the full description…
This may be similar to 1657144, but this particular test case (that has progress bar indeterminite set to true when compare to Windows performs worse on the Mac. In particular the performance on PPC is pretty bad and about 63% worse than the Flash Player Stand Alone.

Overriding methods

January 29th, 2008 ActionScript

This all seems very simple, and once you start designing things in any form of OO way you learn that you need to “extend” a core object and change some of the functions it implements. Generally, the “base” object (initial object) is called a “base class” or “superclass”. The object that extends it is called a “subclass”.

Subclassing is simply a general term for extending an object.

You will almost certainly run into error messages when attempting these extensions. Basically you will have to make sure the base class methods you are extending fit the following rules:

  1. NOT MARKED AS FINAL: The instance method is not declared with the final keyword in the base class. When used with an instance method, the final keyword indicates the programmer’s intent to prevent subclasses from overriding the method.
  2. NOT PRIVATE: The instance method is not declared with the private access control specifier in the base class. If a method is marked as private in the base class, there is no need to use the override keyword when defining an identically named method in the subclass, because the base class method will not be visible to the subclass.

I would add my own to this list:

  1. NOT STATIC: Static methods are both NOT INHERITED and NOT OVERRIDABLE

Adobe has put a great document together to outline this and many other things relating to inheritance.

http://livedocs.adobe.com/labs/flex3/html/help.html?content=04_OO_Programming_11.html

Binding to Getter/Setter methods

January 28th, 2008 ActionScript, Flex

This is a tough one to write about. I can’t say I agree with the outcome, as it’s overly complex. But it’s what there is:

 

The problem:

I had to have a “label” on an object that was read-only but bindable. Basically, this means that I had to write a getter method for label. But as I found out, the flex compiler does not enable binding on read-only properties. This means if you create a getter method without a setter method binding will not fire. At all. Ever.

 

Even if you define your class as [Bindable]. So that I’m clear on this:

 

READ-ONLY PROPERTIES ARE NOT BINDABLE!

 

Okay, now that I’ve said that clearly. Let me tell you how I solved this. Recall I called it ugly.

 

All I had to do was create a setter method for the property which was private. That way external interfaces won’t be misled in believing they can “set” a value on the property (thus maintaining the read-onlyness).

 

Nice, huh?

 

image

Flash of the year — as decided by Adobe

January 10th, 2008 Flash, Presentation

Want to take a quick look at some of the best sites of 2007 to inspire the things you’re working on for tomorrow?

 

This isn’t really Flex or AIR related, but it sure shows a whole array of display possibilities.

 

http://www.adobe.com/devnet/flash/articles/fwa_2007.html

 

 

 

image image
image image
image image

ActionScript 3 Tips and Tricks

January 10th, 2008 ActionScript

http://www.kirupa.com/forum/showthread.php?t=223798

 

I don’t know how I missed it, but it has a great list of AS3 functions and tips. Give it a scour

URLLoader stream error handling

January 10th, 2008 ActionScript

Actually, this has to do with asynchronous error handling, the URLLoader is just a common example of it.

 

Basically, since the call is async a try..catch..finally block won’t do you a beans bit of good. It takes a while for the loader to determine the url is bad and then it dispatches the IO_ERROR event.

 

What this means to your app is that if you don’t listen and handle this event the application will throw ugly errors.

 

To handle this do something along the lines of:

 

 

var loader:URLLoader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR, catchIOError);
function catchIOError(event:IOErrorEvent){
trace(”Error caught: “+event.type);
}
loader.load(new URLRequest(”Invalid XML URL”));
trace(”Continuing with script…”);

rollOver and rollOut — ignore those child mouse events!

January 10th, 2008 ActionScript

Finally, someone has heard the frustration of all of us. We use mouseOver and mouseOut on an HBox and have to either handle all child mouseOver and Outs ourselves, or do the old mouseEnabled = false nonsense — which isn’t usually what we want anyway.

 

spriteButton.addEventListener(MouseEvent.ROLL_OVER, over);
spriteButton.addEventListener(MouseEvent.ROLL_OUT, out);

 

As found on:

http://www.kirupa.com/forum/showthread.php?p=1948052#post1948052

 

Both sets of events determine when a mouse enters or leaves the graphics area of an interactive object. The rollOver and mouseOver events fire when the mouse comes in contact with an interactive object, while rollOut and mouseOut occur when the mouse leaves the interactive object.
Where they differ is with their interaction with interactive object children. The roll events (rollOver and rollOut) simplify the process and prevent interference with child events. Essentially, this is the same as using mouseOver and mouseOut with mouseEnabled set to false. mouseOver and mouseOut with mouseEnabled provide a parent sprite with events from its children. rollOver and rollOut keeps the events on the parent object.

Detecting when the mouse leaves your movie

January 10th, 2008 AIR, ActionScript, Flex

I have tried tons of “mouseOut” and lose-focus types of solutions to deal with my AIR applications losing focus. Well, as of ActionScript 3 I find there is a new event (on the stage itself) which is published when the mouse leaves the movie.

 

stage.addEventListener(Event.MOUSE_LEAVE, myMouseOutFunction);

Finally!

Dispatching an event — custom style

January 10th, 2008 ActionScript, Flex

Let’s say you just wrote a great AS3 class that extends something non-UI. Now when you’re done you want to dispatch an event but you don’t inherit “dispatchEvent” since you’re outside of UI classes (which inherit the event dispatcher).

 

This one has plagued me. In fact there are so many classes in my projects which shouldn’t be extending anything but I ended up extending UIComponent just to get the event dispatcher. Well, I’m here to learn you up on not having to do this hack.

 

ActionScript Code:
package {
   
    import flash.display.Sprite;
    import flash.events.Event;
   
    public class MyDispatcher extends Sprite {
       
        public function MyDispatcher() {
            var dispatcher:CustomDispatcher = new CustomDispatcher();
            dispatcher.addEventListener(“customEvent”, handleEvent);
            dispatcher.dispatchEvent(new Event(“customEvent”));
        }
       
        private function handleEvent(event:Event):void {
            trace(event.type); // “customEvent”
        }
    }
}

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;

class CustomDispatcher implements IEventDispatcher {

    private var eventDispatcher:EventDispatcher;
       
    public function CustomDispatcher() {
        eventDispatcher = new EventDispatcher(this);
    }
   
    public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
        eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
    }
    public function dispatchEvent(event:Event):Boolean {
        return eventDispatcher.dispatchEvent(event);
    }
           
    public function hasEventListener(type:String):Boolean {
        return eventDispatcher.hasEventListener(type);
    }
           
    public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
        eventDispatcher.removeEventListener(type, listener, useCapture);
    }
           
    public function willTrigger(type:String):Boolean {
        return eventDispatcher.willTrigger(type);
    }
}

from http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603

AIR: List of all opened windows

January 2nd, 2008 AIR, ActionScript

I was hunting around today for all opened windows in my application. Seemed obvious enough and something Adobe would have included in the environment — and they did. But it was not something simple to find a reference to, so I thought I’d throw this post out there in the ether. Maybe someone else will find it useful.

 

var windows:Array = NativeApplication.nativeApplication.openedWindows;

 

image

 

Beautiful. And this opens up some other interesting possibilities:

 

Represents this native AIR application.

The NativeApplication class provides application information, application-wide functions, and dispatches application-level events.

NativeApplication is a singleton object, created automatically at application startup. Get the NativeApplication instance of an application with the static property NativeApplication.nativeApplication.

(from the api)

 

There are some interesting items in there:

 

Of course I was already using several of these for my tray-icon and menus and such, but I didn’t know the window list was in here too.