LuciferTian2010
LuciferTian2010

Reputation: 413

What is the sequence for creationComplete, activate, viewActivate and addedToStage and what are they doing?

I am the freshman for flex and actionscript. I want to know when a mobile app initiates, what is the sequence for calling these methods and what are actually they doing separately. I am confused about these functions: creationComplete, activate, viewActivate and addedToStage for begining the app and deactivate and ViewDeactivate for closing the app.

Here is the code I wrote to test about it.

<?xml version="1.0" encoding="utf-8"?>
<s:View viewDeactivate="viewDeactivate()"
    deactivate="deactivate()"
    addedToStage="addedToStage()"
    viewActivate="viewActivate()"
    activate="activate()"
    creationComplete="init()" 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:flextras="http://www.flextras.com/mxml">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[

        private function viewDeactivate():void{
            trace("viewDeactivate");
        }

        private function deactivate():void{
            trace("deactivate");
        }

        private function addedToStage():void{
            trace("addedToStage");
        }

        private function viewActivate():void{
            trace("viewActivate");
        }

        private function init():void{
            trace("creationComplete");
        }

        private function activate():void{
            trace("activate");
        }

    ]]>
</fx:Script>

I just run it on Android mobile phone and the first time I run it and close it, it displays:

creationComplete
viewActivate
addedToStage
viewDeactivate
deactivate

And the then I open and close it again and again, it always displays:

viewActivate
activate
viewDeactivate
deactivate
viewActivate
activate
viewDeactivate
deactivate

Only when I use Android system setting to "force close" the app, then I run it, it again displays:

creationComplete
viewActivate
addedToStage
viewDeactivate
deactivate

So does anybody know why the first time I run it it only display "viewActivate" but no "activate" and for the future when I run it, it displays both but miss "addedToStage" and "creationComplete"? Anybody could tell me what are these functions used for? What things they actually do? And why the sequence displays like that? Also does anybody know what's the difference between "activate" and "viewActivate" and also "deactivate" and "viewDeactivate“?

Thanks!

Upvotes: 0

Views: 3264

Answers (2)

Andr&#233; Ricardo
Andr&#233; Ricardo

Reputation: 1

Android has a Lifecycle (http://developer.android.com/training/basics/activity-lifecycle/starting.html) and i think that's the reason why these events aren't fired every time you "open" the app.

Upvotes: 0

user797257
user797257

Reputation:

activate event is inherited from EventDispatcher (the default implementation of event dispatching class present in the player runtime). This class is usually extended by other classes if they want to be able to dispatch events. This particular event is dispatched "when the Flash Player or AIR application gains operating system focus and becomes active" Note that it is a broadcast type event, which means that you don't need to listen to any particular dispatcher, it is invoked on any existing listener.

addedToStage is dispatched when the listener is added to display list (it's properties such as stage, parent and loaderInfo are populated and, potentially, it can start receiving interaction events, such as mouse events, touch events etc.) This is one of the basis events available to all display objects.

viewActivate is a specific to mobile devices event dispatched by classes inheriting from spark.components.View. So far I understand, it is dispatched once the view (which dispatches it) becomes visible to the user.

creationComplete is a specific to Flex framework event. It will be dispatched by View class mentioned above, because it is an extension of UIComponent, which is the core component of the Flex framework. This event is dispatched once all of the components properties declared in MXML template were set, the component finished it's validation cycle, being laid out etc.

Most unfortunately, according to Adobe design you must use Flex framework in order to access certain features on mobile devices. This is why you have that lot of initialization events - the Flex framework is bloated with redundant or very similar classes, functions etc.

Upvotes: 2

Related Questions