-
Error using stage.stageWidth [Flex 3]
Hello All
Im trying to accessing the stageWidth value of the main application.
But it gives compile time error 1009 that im trying to access a null pointer.
Please help.
-
supervillain
Care to post your code?
I tend to use width="{DEFAULT_WIDTH}" in my mx:Canvas, then use in my mx:Script something like private static const DEFAULT_WIDTH:Number = 500 or so.
But just wondering what all do you have set up and how.
-
Thanks for the reply
Actually after loading the file using swfloader, i want to adjust it according to the stage size.
Still it gets NULL Error
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
private function hello():void{
trace(stage.stageWidth);
}
]]>
</mx:Script>
<mx:VBox verticalCenter="-13" height="410" x="787" width="215" horizontalAlign="center" verticalGap="0">
<mx:SWFLoader source="images/raza.swf" autoLoad="true" id="raza" complete="hello()"/>
</mx:VBox>
</mx:Application>
-
-
supervillain
I didn't have any problems with your code. Just make sure that you have an /images/raza.swf in your /bin folder alongside the compiled - once you build - *.swf and html file.
I just tested without a problem. Created a test.mxml, copied and pasted your code, created a bin-debug folder - usually I just use bin, but was using the default settings and since I'm on my Vista machine, it ended up in C:\Users\gerbick\Documents\Flex Builder 3\test\src for the test.mxml. In my bin-debug folder, test.swf and test.html. and in \images, raza.swf - a simple Swift3D animation I had made real quick.
And it worked.
I'd just make sure you have a *.swf in the location that's specified. It's relative to the location of your compiled *.swf, not the *.mxml.
Hope that helps... sorry for the delay.
-
SWF file is loading File
Problem is with stage.stageWidth property!
It gives a Runtime Error
Try following code
Im using FLEX 3
Thanks
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
private function hello():void{
if(stage.stageWidth > 800){
raza.enabled = true;
}
}
]]>
</mx:Script>
<mx:VBox verticalCenter="-13" height="410" x="787" width="215" horizontalAlign="center" verticalGap="0">
<mx:SWFLoader source="images/raza.swf" autoLoad="true" id="raza" complete="hello()"/>
</mx:VBox>
</mx:Application>
-
supervillain
I too am using Flex 3.
You're not stating where the problem is coming from. Let's try to locate that first... you're experiencing an error when? On load? On run? Within the Flex IDE? Via debug? When?
Any code in the *.swf are you using?
-
supervillain
In fact, here's a screenshot of my version. I'm using your code, only difference is that I'm using a cube animation with a bitmap texture - two seconds only - with no AS in the *.swf. Not even a stop();
-
Thanks a lot for your constant feedback and help.
I modified the code and make it more simple to detect the error.
When i save the file, it doesnt show any error.
But when i run it. It gives error in internet explorer [runtime error]
This is code
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="hello()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
private function hello():void{
trace(stage.stageWidth);
}
]]>
</mx:Script>
</mx:Application>
And this is the error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at index/hello()[C:\Documents and Settings\Ali RAZA\My Documents\Flex Builder 3\serv\src\index.mxml:7]
at index/___index_Application1_creationComplete()[C:\Documents and Settings\Ali RAZA\My Documents\Flex Builder 3\serv\src\index.mxml:2]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:9051]
at mx.core::UIComponent/set initialized()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:1167]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ managers\LayoutManager.as:698]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:8460]
at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:8403]
-
I believe your problem is that the stage.stageWidth is "unknown" early in a movie's initialization, say frame #1. Look it up in Flash documentation to read.
This should work fine for you:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
horizontalScrollPolicy="off"
verticalScrollPolicy="off" >
<mx:Script>
<![CDATA[
private function hello():void{
trace(stage.stageWidth);
}
]]>
</mx:Script>
<mx:Button label="test" left="100" top="100" click="hello()" />
</mx:Application>
gsb
-
...OH (continued)
...and if you REALLY need the stageWidth at the 'creationComplete' event processing time you can do something like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
creationComplete="onCreationComplete()" >
<mx:Script>
<![CDATA[
private var myStageWidth:Number;
private function hello():void{
trace("stage.stageWidth: "+stage.stageWidth);
}
override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ) : void
{
super.updateDisplayList( unscaledWidth, unscaledHeight );
trace("unscaledWidth: "+unscaledWidth);
myStageWidth = unscaledWidth;
}
private function onCreationComplete():void{
trace("myStageWidth: "+myStageWidth);
}
]]>
</mx:Script>
<mx:Button label="test" left="100" top="100" click="hello()" />
</mx:Application>
Trace:
unscaledWidth: 915
myStageWidth: 915 <-- creation complete timeframe
unscaledWidth: 915
stage.stageWidth: 915 <-- lastly, button click
-
Thanks a lot []
Now it works Fine, Thanks once again
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|