Archive for the 'Flex' Category

Progress Meters and performance

Thursday, March 13th, 2008

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.

Binding to Getter/Setter methods

Monday, January 28th, 2008

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

Detecting when the mouse leaves your movie

Thursday, January 10th, 2008

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

Thursday, January 10th, 2008

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