Adobe AIR iOS/Android best event to listen for in AS3

1.3k views Asked by At

So I'm having this issue where I need an event to fire at the very beginning of my application

public function Main() {    
            this.addEventListener(Event.ACTIVATE, onInit);
        }

I've also tried Event.ADDED_TO_STAGE, but both seem to not be firing onInit at the right time... they fire too early. For example, on testing for IPhone it's firing when I still see the Default.png icon... I want it to fire when that "loading" phase is over.

3

There are 3 answers

1
Alan Klement On

Have you checked out this:

Look in the AIR API and not within the Events package. Here and here.

0
Dave Wolfe On

"The very beginning" should be defined better :) Activate, Invoke, and Added to Stage events all fire at various stages of the beginning of your app. If you want to wait for the app to actually appear on screen, you should wait for an enter frame or render event.

0
Alex On

I have a solution for your problem if i understand it well. I came to this thread by searching the same thing but the above answers were not a fix so i took matters into my own hand. What i wanted to achieve is to get a fast startup for my app with a "splash screen". Then as soon as my app was launched "completely" (by completely i mean when the android animation for launching it was over and i was actually seeing the pixels of my splash screen) i wanted to call my "init function" to start some heavy code of loading assets / generating stuff (therefore avoiding a long duration black screen). There IS NO event to trigger for this at the right time. They all fire to early because the android must load the whole app at startup before displaying any actual pixels from it. They all fire to soon, unlike the desktop environment when a combination of event.ACTIVATE and event.FRAME_CONSTRUCTED/event.RENDER or onEnterFrame did the trick.

Solution: Use a loader swf as your main app. Load your app into the loader. Android will load first your loader and will let flash render the stage at witch point you have your "beloved" event :D. If you think this solves your problem but need more help i will be happy to clarify more.