You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by leokan23 <le...@best-web.gr> on 2018/12/06 19:27:39 UTC

Stage use in Flex?

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/

Re: Stage use in Flex?

Posted by leokan23 <le...@best-web.gr>.
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/

Re: Stage use in Flex?

Posted by After24 <vi...@after24.net>.
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/

Re: Stage use in Flex?

Posted by Douglas McCarroll <li...@brightworks.com>.
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 <
list.apache-flex.001@brightworks.com> 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 <le...@best-web.gr> 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/
>>
>>

Re: Stage use in Flex?

Posted by Douglas McCarroll <li...@brightworks.com>.
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 <le...@best-web.gr> 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/
>
>

Re: Stage use in Flex?

Posted by Lydecker <za...@zizunetwork.co.uk>.
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/

Re: Stage use in Flex?

Posted by After24 <vi...@after24.net>.
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/