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>
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
...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
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>
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
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;
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
Copy link to clipboard
Copied
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