Stage use in Flex?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Stage use in Flex?

leokan23
I am trying to use stage to add an admob banner in my flex app but it fails
when I use this:

stage.stageWidth / 2

How can I use stage inside a Flex app? I can't find any info.



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

After24
Hi Leokan,

Do you get an NPE when you try to access the stage object ?

You could try to use /FlexGlobals. topLevelApplication.stage/

Vincent.



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

Lydecker
Make sure the stage is available/created when referencing it. If you are
getting a null error - it might be because the stage is not available yet -
this can happen when you call stage in the applications
contentCreationComplete /init handler.

I always use

if(stage){
stage.color = ..... //access stage
}

that way if the stage isn't available, it won't error.



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

douglasmccarroll
In reply to this post by leokan23
Searching through my code I see one place - in a subclass of
spark.component.View - where I do this:

if (stage) {
   onAddedToStage();
}
else {
   addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

There may be other classes in Flex that have a stage property - I'm not sure...

In any case, you should ensure, as above, that the class has been
added to the stage before trying to reference the stage property.

Douglas




On Thu, Dec 6, 2018 at 2:27 PM leokan23 <[hidden email]> wrote:

> I am trying to use stage to add an admob banner in my flex app but it fails
> when I use this:
>
> stage.stageWidth / 2
>
> How can I use stage inside a Flex app? I can't find any info.
>
>
>
> --
> Sent from: http://apache-flex-users.2333346.n4.nabble.com/
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

douglasmccarroll
Looking a bit further, I see that View inherits 'stage' from DisplayObject,
so any subclass of DisplayObject will have it...

On Thu, Dec 6, 2018 at 7:57 PM Douglas McCarroll <
[hidden email]> wrote:

> Searching through my code I see one place - in a subclass of
> spark.component.View - where I do this:
>
> if (stage) {
>    onAddedToStage();
> }
> else {
>    addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
> }
>
> There may be other classes in Flex that have a stage property - I'm not sure...
>
> In any case, you should ensure, as above, that the class has been added to the stage before trying to reference the stage property.
>
> Douglas
>
>
>
>
> On Thu, Dec 6, 2018 at 2:27 PM leokan23 <[hidden email]> wrote:
>
>> I am trying to use stage to add an admob banner in my flex app but it
>> fails
>> when I use this:
>>
>> stage.stageWidth / 2
>>
>> How can I use stage inside a Flex app? I can't find any info.
>>
>>
>>
>> --
>> Sent from: http://apache-flex-users.2333346.n4.nabble.com/
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

After24
The advantage of using /FlexGlobals. topLevelApplication.stage/ is that the
Application component is already added to the display list at the time you
want to access the stage object within you application content.

Vincent.




--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Stage use in Flex?

leokan23
Ok so it looks like the problem was using the stage way to fast via the
creationComplete :)

I added a listener to check that the stage is already added, and now it
works.

Thank you guys.



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/