Very strange Adobe AIR bug...

blue44
blue44 used Ask the Experts™
on
Hi Experts,

I have an AIR application that makes some http calls -- simply enough.  This works when I run the app in Flex Builder but after I package the application and run the exe, the calls are never made.  Even stranger, if I add an alert before the call in the method, then the http call is made.  This makes no sense to me and I was wondering if someone could help shed some light on this.  The code is below:

My config is as follows:

Flex 3.3 SDK
AIR 1.5
Cairngorm

BTW, I'm tracking whether these calls are made via the http sniffer, Charles.

Thanks!!
public function refreshCurrentStatusPanel():void{
              //Alert.show("hi");
		var event:SetDateEvent = new SetDateEvent();
		event.dispatch();
		var event2:GetCurrentStatusEvent = new GetCurrentStatusEvent();
		event2.dispatch();
		var event3:GetDailyMaxMinEvent = new GetDailyMaxMinEvent();
		event3.dispatch();
		var event4:GetRawGraphEvent = new GetRawGraphEvent();
		event4.dispatch();
}
 
<mx:Button id="btnRefresh" toolTip="Refresh" 
		                icon="@Embed('assets/refresh.png')" 
		                width="18" 
		                height="18" 
		                click="refreshCurrentStatusPanel()" />

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Well, your event objects are locally defined within the scope of the function.
It seems that without the Alert call, that function might be executed 'too fast' and as soon as it exits the event objects go out of scope and are (possibly) garbage collected before they've had a chance to 'make their calls'.
With the Alert, seems it's giving flex enough time, maybe through a screen frame update, for the event objects to actually make their calls before being disposed.

All a bit vague without being able to fully trace the code through.

Can you try defining the event objects outside the scope of that function and see what happens?


private var event:SetDateEvent = new SetDateEvent();
private var event2:GetCurrentStatusEvent = new GetCurrentStatusEvent();
private var event3:GetDailyMaxMinEvent = new GetDailyMaxMinEvent();
private var event4:GetRawGraphEvent = new GetRawGraphEvent();
 
public function refreshCurrentStatusPanel():void{
              //Alert.show("hi");
                event.dispatch();
                event2.dispatch();
                event3.dispatch();
                event4.dispatch();
}
 
<mx:Button id="btnRefresh" toolTip="Refresh" 
                                icon="@Embed('assets/refresh.png')" 
                                width="18" 
                                height="18" 
                                click="refreshCurrentStatusPanel()" />

Open in new window

Author

Commented:
Thanks so much for getting back to me.  I tried your suggestion and it worked...the first time.  That is, the first time the button is selected and the function is called, the http calls are made.  Any subsequent call, however, doesn't do anything? Any ideas what might be going on now?
//yes, I changed the event names around just so the reserved word event wasn't being used.
private var event2:SetDateEvent = new SetDateEvent();
private var event3:GetCurrentStatusEvent = new GetCurrentStatusEvent();
private var event4:GetDailyMaxMinEvent = new GetDailyMaxMinEvent();
private var event5:GetRawGraphEvent = new GetRawGraphEvent();
 
public function refreshCurrentStatusPanel():void{
                event2.dispatch();
                event3.dispatch();
                event4.dispatch();
                event5.dispatch();
 
}

Open in new window

Commented:
OK, I don't know what your code does inside the 'dispatch' methods, but sounds like they can only be used once.
So create new objects on each call.

Try:


//yes, I changed the event names around just so the reserved word event wasn't being used.
private var event2:SetDateEvent;
private var event3:GetCurrentStatusEvent;
private var event4:GetDailyMaxMinEvent;
private var event5:GetRawGraphEvent;
 
public function refreshCurrentStatusPanel():void{
                event2 = new SetDateEvent();
                event3 = new GetCurrentStatusEvent();
                event4 = new GetDailyMaxMinEvent();
                event5 = new GetRawGraphEvent();
                event2.dispatch();
                event3.dispatch();
                event4.dispatch();
                event5.dispatch();
}

Open in new window

Author

Commented:
That did it...thanks so much!!! I wonder if this was all due to the fact that Cairngorm's event model isn't made for AIR apps.

Author

Commented:
Excellent advice!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial