Showing posts with label flex4. Show all posts
Showing posts with label flex4. Show all posts

Monday, 13 June 2011

Flex4, how to wait object to be completely initialized; how to give time to objects to be completely initialized


Suppose that you have an Object called Circus. This object is too complex (like a real circus). The follow init() function creates the circus it but in real programming world the Circus object is not prepared because the Circus must be render its components, update several graphics objects .

internal function init():void{
       //create my.. circus…
       myCircus=new Circus(“My X-circus");
       //initialize
       myCircus.x=10; myCircus.y=40;
       //play
       myCircus.play();
       myCircus.cashier.addMoney(100.50); //this might be wrong, as the circus in not ready yet!
}

This problem occurred on simpler objects also… like the Flex’s Label. If on “applicationComplete” you apply a value to “text” property of a Label a text (i.e. “hellow world”) and right after you try to get the “width” of the Label object, you might be get WRONG value, a not real width; this because the Label object is not yet prepared.
Well, how to get that an object is completed? With Flex’s Label, the event you must Listen is the “FlexEvent.UPDATE_COMPLETE” and not other “UPDATE_COMPLETE” because Flex offers and other from other Eventxxx classes. Note that this is working in Flex 4.0.

So… the Circus object must supports and dispatch once upon a time the “FlexEvent.UPDATE_COMPLETE” to continue in safe way the calculations with its properties.

But, what happen if the Circus doesn’t supports this event? Unfortunately this is happening in real world with several 3rd party components / object.

Bellow there is a solution that is not so professional but it is the only chance to make it work! ;) What I do here is that I am working for a while with Event.ENTER_FRAME, with this way I give some time to then whole application and its running objects to complete uncompleted calculations.

//this is my own counter to count the passed time.
internal var myWaitCounter:int;

internal function init():void{
       //create my.. circus…
       myCircus=new Circus(“My X-circus");
       //initialize
       myCircus.x=10; myCircus.y=40;
       //prepare and activate my listener pf ENTER_FRAME event
       myWaitCounter=0;
       addEventListener(Event.ENTER_FRAME,Handler_WaitForCompletion);
}

internal function Handler_WaitForCompletion (e:Event):void{
       //add to my counter the time
       myWaitCounter+=1000/ Object(FlexGlobals.topLevelApplication).stage.frameRate;
       //if, 500ms (0,5sec) passed, then call the start() after remove then listener
       //in general it is very important to remove the listeners where you don’t need any more
       if (myWaitCounter >=500) {
              removeEventListener(Event.ENTER_FRAME,Handler_WaitForCompletion);
              start();
       }
}

protected function start():void{
       //now you are ready to play with you circus safely!
       myCircus.play();
}


Monday, 31 January 2011

Flex4, event MOUSE_OUT is triggered for every MOUSE_OUT event of its children

problem:
Suppose you have a Group or Module named MainMenuItem, where you have several other childer components in it. You want when mouse gets of the MainMenuItem to colapse it, in order to create a pull down menu. The problem is that Flash runtimer returns the MOUSE_OUT event where ever this happen in the children of the MainMenuItem.

solution
Do not strangle with "bubbles" and "stop.propagation", I tried, they didn't work. In the implementations of the Listener, just check if the target of the event is children indeed; and if its not, do perfrom the action you want (the collapse in this example); because in real the mouse is not out but it is still over on your Group (or Module).

Monday, 10 January 2011

adobe, flex4, the whole Eclipse environment freezes with CPU at 99%

environment: adobe flex4 AS3.0 Eclipse ide

problem: the whole Eclipse environment freezes with CPU at 99% and never becomes normal


solution: 
it IDE's bug, if you have remarked text in the are of arguments of a function... move them somewhere else
i.e.
  public function newItem(
   /**HELP, creates a new item */
   name:String
  ){
    ....
  }

the red text indicates the wrong remarked text

adobe flex4 AS3.0, eclipse IDE, the code insight doesn't insights

environment: adobe flex4 AS3.0 with eclipse ide

problem: on design time, creating a object with "new operator", the code insight doesn't show the required arguments by the constructor of the class

solution: the arguments appeared when I removed the ":void" from the constructor… this is not so usual!

Saturday, 8 January 2011

adobe Flex4 AS3.0, Canvas component is abandoned!!! which is our new game?

Which component will replace the favorite Canvas?
Play with spark.Group container! I say "play" because you have to do some work.
Read how you can do the same things in flex4 and spark components.
Note!: this post doesn't cover components and general solution with skin-able components!

History:
Fact is that canvas was the favorite object for lo fex4 level programming. Now Adobe is messing up our code saying that will not support any more the Canvas object, instead will work with Group container object. The good news is whatever complex is Group, it is lighter and more flexible than Canvas.

Problem:
Which is the new component?

Solution:
There are 2 respectively components instead of canvas. The Bordercontainer is subclass of SparkContainer and it is skinable. But it is heave in swf size and it is not good for low level programming. 

The Group component:
  • is almost like a Canvas, 
  • more lighter in swf , 
  • it is not skin-able,
  • it doesn't scroll its contain
  • and by default the contained stuff is appeared also outside of its region!
To make the Group component to work like the old (and favorite) Canvas you have to do:

1. Set the Group property clipAndEnableScrolling to true, so the contents will be appeared on their parts in the region of Group.

2. Add scroll bars. Add a Scroller Component into your stage, and in Scroller  add a Group component, so the Group will be in the Scroller component. Set the vertical/horizontalScrollPolicy to true as you desire. Scroller component doesn't accept simple components like Label.

3. Visual Anchors / constraints of our container

on design time...
Group should have Width and Height the value "100%" (this value is accepted on design time). With this value, the group will always stretched in Scroller's maximu area its time.

Scroller may have any kind of Constraints or absolute x,y,width&height, the location of the Scroller will define the location of our Group.


...keep coding...