Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-19-2007, 05:07 AM   #1
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default stage.stageWidth returning 0

I am trying to get the stage height and width. But Flex is returning the value 0. However, if I write the code for mouse click it is working fine. I can not figure it out why it is not working.

Here is my code:

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
	<![CDATA[
		import mx.controls.Alert;	
		
		private function init():void
		{
			Alert.show("Stage Width"+stage.stageWidth)
		}
		
	]]>
</mx:Script>
<mx:VBox id="mainVB" creationComplete="init()">
	<mx:Button label="Click Here" click="Alert.show('Stage Width '+stage.stageWidth)"/>
	<mx:TextArea width="300" height="400"/>
</mx:VBox>	
</mx:Application>
I simply want to center the VBox according to the stage
salim_designer is offline   Reply With Quote
Old 11-19-2007, 09:34 AM   #2
Daedalus
Flexified
 
Join Date: Aug 2005
Location: Bath, UK
Posts: 127
Default

as stage is a class dosent it start with a capital S?

Stage.stageWidth

just a thought

You could aviod the use of stage by using the vBoxes horizontalCenter and verticalCenter property, setting it to 0.

Also I think you can only access stage once the object you are accessing it from is on the stage. Maybe try putting the mxScript inside the vbox tags. I dont use MXML so I could be wrong here.

Insted of calling the init() function on creationComplete try using Event.ADDEDTOSTAGE, this might help.
Daedalus is offline   Reply With Quote
Old 11-19-2007, 10:09 AM   #3
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default

Thank you for your reply

Capital S for stage.stageWidth does not work. Yes I know we can use vBoxes with horizontalCenter and verticalCenter but I am working with a customized window which requires to become full screen on a button click and again resize to its original size and position on another button click. Unless I calculate the stagewidth and height I can not center the window(with Animation).
salim_designer is offline   Reply With Quote
Old 11-19-2007, 12:32 PM   #4
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default

Can anyone please let me know where I am making the mistake
salim_designer is offline   Reply With Quote
Old 11-19-2007, 05:21 PM   #5
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

Try listening for the stage's resize event. In some browsers, the stage resizes a couple times before it finally reaches the intended size.
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 11-20-2007, 03:51 AM   #6
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default

Ok this is fine but I would just like to know, why we can not get the value of stage width and heigth by using stage.StageWidth .....

Is this a bug or I am using wrong procedure.
salim_designer is offline   Reply With Quote
Old 11-20-2007, 05:43 AM   #7
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default

I tried using the stage's resize event but it is not working and I am getting the following error:

1) Call to a possibly undefined method addEventListener through a reference with static type Class

2) Access of undefined property showBox

Here is my code:

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
	<![CDATA[
		import mx.controls.Alert;
		[Bindable]
		private var sWidth:int;
		
		[Bindable]
		private var sHeight:int;	
		stage.addEventListener(Event.RESIZE,showBox);
		
		private function showBox(event:Event):void
		{
			mainVB.visible=true;
			sWidth = stage.stageWidth;
			sHeight = stage.stage.stageHeight;
			mainVB.x = (sWidth/2)-(mainVB.width/2);
			mainVB.y = (sHeight/2)-(mainVB.height/2);
		}
			

		
	]]>
</mx:Script>
<mx:Button x="800" y="0" label="Click" click="showBox(event)"/>
<mx:VBox id="mainVB" width="300" height="400" visible="false" backgroundColor="#cccccc">
	<mx:Button label="Click Here" click="Alert.show('Stage Width '+stage.stageWidth)"/>
	<mx:TextArea width="200" height="200"/>
</mx:VBox>	
</mx:Application>
salim_designer is offline   Reply With Quote
Old 11-20-2007, 05:36 PM   #8
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

You're listening for the resize event in the wrong place. The stage variable is not defined as a static variable. Put it in a function, such as a handler for the applicationComplete event.
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 11-21-2007, 03:23 AM   #9
salim_designer
Senior Member
 
salim_designer's Avatar
 
Join Date: Oct 2005
Location: Kolkata, India
Posts: 199
Default

Wow! That's great. Thank you dr_zeus
salim_designer is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
setInterval and returning from a class function martyf ActionScript 2.0 0 10-14-2007 09:39 AM
Returning the values of a shuffled array orlando ActionScript 2.0 4 12-13-2006 03:12 PM
"this" returning null, and Stage.width/Stage.height returning 0 ?? infernalRyan ActionScript 2.0 12 09-24-2006 03:25 PM
getRGB() returning 0 for MovieClip ovlnmurty ActionScript 2.0 1 02-23-2006 11:02 AM
onMetaData returning false height billstoudt ActionScript 2.0 1 06-28-2005 02:31 PM


All times are GMT. The time now is 04:20 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.