• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

trace stage width

Explorer ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

I'm trying to trace out the width of the stage, but I can't figure out how to get the stage object. This code throws a null object reference error.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import flash.display.Stage;
            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                trace(stage.stageWidth);
            }
        ]]>
    </fx:Script>
</s:WindowedApplication>

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Oct 02, 2010 Oct 02, 2010

Well I'm not sure what you are going for based on the code you pasted since the blueberry variable would never be set in the current code. So I'm assuming you wanted to set the blueberry variable to the width of the stage and then access it later on? If that's the case,

(forgive the formatting, pasting from FB on the Mac never goes well in the forums)

<?xml version="1.0" encoding="utf-8"?>

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                xmlns:s="library://ns.adobe.co

...

Votes

Translate

Translate
Participant ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Since you have this in a function called once the appliction is complete you should just be able to use

trace(this.width);

this would refer to the application window in this case and will get the width for you.

Regards,

Peter Witham

www.uibuzz.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Thanks. What about setting it outside the function? Like:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import flash.display.Stage;
           
            private var blueberry:Number = this.width;
           
            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                trace(blueberry);
            }
        ]]>
    </fx:Script>
</s:WindowedApplication>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Well I'm not sure what you are going for based on the code you pasted since the blueberry variable would never be set in the current code. So I'm assuming you wanted to set the blueberry variable to the width of the stage and then access it later on? If that's the case,

(forgive the formatting, pasting from FB on the Mac never goes well in the forums)

<?xml version="1.0" encoding="utf-8"?>

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                xmlns:s="library://ns.adobe.com/flex/spark"

                  xmlns:mx="library://ns.adobe.com/flex/mx"                                                      creationComplete="windowedapplication1_creationCompleteHandler(event)">

     <fx:Script>

          <![CDATA[

      import mx.events.FlexEvent;

      import flash.display.Stage;

             private var blueberry:Number;

      protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void

      {

           this.blueberry = this.width;

      }

      private function getApplicationWidthSomeOtherTime():Number

             {

                return this.blueberry;

             }

    ]]>

     </fx:Script>

</s:WindowedApplication>

And you just call getApplicationWidthSomeOtherTime when you want the width. So you could for example

trace(getApplicationWidthsomeOtherTime());

Regards,

Peter Witham

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Thanks, the code isn't really for anything. How would you set the variable outside the function? Something like:

private var blueberry:Number = this.width;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Actually now that I think about it, you could bypass a lot of this by directly calling

trace(nativeWindow.width);

Are you looking to change the variable value? In which case you'd really want to use a getter/setter set-up to do it, or actually change the size of the window applcation? Which would be different code.

Feel free to mark this question answered and ask a new one if you want to change the window application size at run time to help people searching the forums in the future.

Regards,

Peter Witham

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

LATEST

I created a video with some code that I think might help answer the questions for you

http://www.uibuzz.com/?p=1333

Enjoy, plenty more on the site.

Regards,

Peter Witham

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines