StageWidth ?
This code works perfectly except when I make reference to the stage width/height.
I get a error like "TypeError: Error #1009: can't make reference to a null object"
What's going on?
(yes I'm a AS3 newbie)
Code: package{ import flash.display.MovieClip; import flash.display.Stage;
public class circulo extends MovieClip{ public var radio:Number;
public function circulo(){ radio = Math.floor(Math.random()*100); this.width = radio * 2; this.height = radio * 2; this.x = Math.floor(Math.random() * stage.stageWidth); this.y = Math.floor(Math.random() * stage.stageHeight); } } }
KirupaForum > Flash > ActionScript 3.0
Posted on: 02-20-2008, 06:22 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
StageWidth Question
on the timeline I accessed stageWidth and stageHight just fine...but couldn't in an external class. I used:
Code:
package scripts {
import flash.display.*;
var stageW:int = stage.stageWidth;
public class BaseCode extends MovieClip {
public function BaseCode(){
//nothing here yet
}
}
}
Why didn't it work?
When Would Stage.stageWidth Be Zero?
Hm... I thought that I will always get the correct value on stage.stageWidth if the file is set as a Document class... Is that absolutely correct???
What would be the case when it is set to zero if it is not true???
Thanks...
Flash CS3: Set StageWidth?
I'm building AS3 projects using Flash CS3. Really, just what I tend to be comfortable with because I can quickly mock-up a Movie Clip visually and integrate it.
But the app I'm building is basically a component. I'd like to have the built swf's stage dimensions dynamically set. Is that even possible?
i.e. -> stage.stageWidth = 1440 does nothing. The swf stage's width and height are always determined by the FLA's stage.
Stagewidth Question
Hello,
I'm needing help with some code - I wish to keep a movie clip within the stage of my movie. I tried using hitTests to keep him in but it did not work as intended.
I know the code should go something like this
onclipevent (enterframe)
if(_root.Turrican > stage.width) (_root.Turrican._x=-20)}
I cant the code perfect, any pointers?
Setting StageWidth?
In the ActionScript 3.0 Language Reference, the property stageWidth (of Stage Class) is read-write, and even has a setter.
http://livedocs.macromedia.com/labs/as3preview/langref/flash/display/Stage.html
stage.stageWidth = 800; ==> DOESN'T WORK!!!
Anybody knows why???
StageWidth After Resize
When I resize the stage during execution stage.stageWidth changes as expected, but the 0,0 coorinate seems to ove. When I trace out the stage.mouseX or mouseY coordinates after maximizing the stage I get negative numbers for the upper left hand corner, and the lower right gives numbers that are too low. For instance my normal stageWidth is 550, but when I maximize I get 1020, but the left side of my stage returns a position of -235 and the right side gives 785 (234 + 785 = 1020). Is there a way to reset the base coordinate, or am I doing something wrong?
Kinsey
BUG: StageWidth/Height
In AS3 documentation it says:
Quote:
When the value of the scaleMode property is set to StageScaleMode.NO_SCALE, the stageWidth property represents the width of Flash Player. This means that the stageWidth property varies as you resize the Flash Player window. When the value of the scaleMode property is not set to StageScaleMode.NO_SCALE, the stageWidth property represents the width of the SWF file as set during authoring in the Document Properties dialog box. This means that the value of the stageWidth property stays constant as you resize the Flash Player window. This property cannot be set.
Now, in flash9 with AS3 no matter what the scaleMode is set to when I try to read stageWidth or stageHeight I allways get the size of Flash Player window instead of the SWF file dimensions (as set during authoring in the Document Properties dialog box). Does any of you have this bug? If it's not a bug, then please let me konw how to make this to work.
Regards,
Psykovsky
Using StageWidth & StageHeight
When you are creating a class which needs to know the stage width and height, how do you do this?
Till now I have been passing the stage as a parameter in order to be able to use its properties, but I feel this is not the correct way.
If I just try to use stage.stageWidth in a class, I get an error. Any suggestions?
Could This Be? Stage.stageWidth Not Working?
Iv'e used addChild to add an object to the stage, within this object I have this code:
ActionScript Code:
trace(stage.stageWidth);
My trace result:
ActionScript Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Menu/::frame1()
Huh? Why wouldn't it work?
Cannot Access Stage.stageWidth
with this:
trace(Stage.stageWidth)
i get this error:
1119: Access of possibly undefined property stageWidth through a reference with static type Class.
AS3 - Setting The StageWidth And StageHeight
Hi,
I wish to set the height and width of the stage to 1,000 pixels by 1,000 pixels but my current code is not changing these properties of the stage.
note: I am compiling this AS3 with the Flex 2.0.1 SDK mxmlc.exe AS3 compiler.
My current code is:
package {
import flash.display.*;
public class ExampleApp extends MovieClip
{// constructor
public function ExampleApp()
{ // change stage parameters
stage.stageHeight = 1000;
stage.stageWidth = 1000;
stage.showDefaultContextMenu = false;
// add a sample red square to the display list
var _shpSquare:Shape = new Shape();
_shpSquare.graphics.beginFill( 0xFF0000 );
_shpSquare.graphics.drawRect( 0, 0, 100, 100 );
_shpSquare.graphics.endFill();
addChild( _shpSquare );
}
}
}
Any ideas ?
(note that the line of code to turn the default context menu is working ok)
I only want to set the height and width of the stage once in my application.
Cheers,
MovieClip Overlapping StageWidth ?
Let's say we duplicate a movie clip by clicking on a button. Each time the button is clicked the duplicated movie clip is aligned next to the previous one. How can I "trace" or monitor when the duplicated movie clip reaches/overlaps the stage width. What I'm willing to do is to auto-align the MC in a new line if it overlaps the stage width ( and so on ).
PS: and yeah, after it overlaps the width once, then if I add a new MC it should continue the new line
StageWidth With Zooming The Player Window?
Hello,
I have a movie where I want to periodically create pop-up windows that are centered in the middle of the stage, and I do this by calling a setup function before adding the child with the code:
Code:
this.x = (stage.stageWidth/2 - this.width/2);
this.y = (stage.stageHeight/2 - this.height/2);
When testing it, it works fine. However, if at various points during the movie i try and resize the flash player window, either by dragging it, hitting zoom, or going to full screen, the popup window keeps showing up at very strange locations.
Is there some way I can restrict it to the active stage, or maybe some windowWidth property that i can use to correct this?
Thanks!
Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with a symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.
I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.
Under this type of linkage, is there a way to reference the stage width from the class?
I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.
Below is the code for my .fla file and my .as file. In the .as file you'll see the line "x = Math.random() * stage.stageWidth;". This is the line giving me problems. I could hard code it, as I do for the y variable on the next line, but I'd prefer not to in order to keep the code flexible.
I also attached the files in a zip.
Any help would be appreciated.
ActionScript Code:
//.fla code
var i:int;
for(i=0; i < 100; i++){
var myBall:flaBall = new flaBall();
addChild(myBall);
}
//.as code
package {
import flash.display.*;
import flash.events.Event;
public class Ball extends MovieClip{
var dx:Number;
var dy:Number;
public function Ball(){
addEventListener(Event.ENTER_FRAME, onEnterFrame2);
reset();
}
private function reset(){
x = Math.random() * stage.stageWidth;
y = Math.random() * 400;
dx = Math.random() * 20 - 10;
dy = Math.random() * 20 - 10;
}
private function onEnterFrame2(event:Event):void{
move();
checkBounds();
}
private function move(){
x += dx;
y += dy;
}
private function checkBounds(){
if (x > 550 || x < 0){
dx *= -1;
}
if (y > 400 || y < 0){
dy *= -1;
}
}
}
}
Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with an symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.
I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.
Under this type of linkage, is there a way to reference the stage width from the class?
I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.
Any help would be appreciated.
Browser StageWidth/Height Delay
I'm looking for more information and a solid solution to the delay that some browsers create before stage.stageWidth and stage.stageHeight are set correctly.
Mainly Internet Explorer and Safari seem to affect this badly and I'm not sure when I can expect the stageWidth/Height to have the correct values.
Anyone here who can shed some light on this issue? Thanks in advance.
Errors With StageWidth/stageHeight In Package
hello everyone, I'm trying to make a class that will scale a clip when the stage resizes. I have the Stage resize set to NO_SCALE so the majority of clips on the stage will not scale, however i want to make an exception. So i wrote the package below. However, when i try to run the movie, it throws this error:
1119: Access of possibly undefined property stageWidth through a reference with static type Class.
Obviously i'm missing something and need some help. Thanks in advance.
package bmilesp.display.LayoutTools {
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.display.MovieClip;
public class LayoutTools {
private var _stageOriginalWidth:Number = Stage.stageWidth;
private var _stageOriginalHeight:Number = Stage.stageHeight;
public function scaleWithStage(my_clip:MovieClip):void{
var scaleChangeWidth:Number = Stage.stageWidth/_stageOriginalWidth;
var scaleChangeHeight:Number = Stage.stageHeight/_stageOriginalHeight;
my_clip.width = my_clip.width * scaleChangeWidth;
my_clip.height = my_clip.height * scaleChangeHeight;
}
}
}
StageWidth/stageHeight Initialize Timing?
I'm trying to retrieve the stageWidth/stageHeight on the constructor of document class (correct me if I'm using a wrong term). But it keeps returning me zero, until the first frame is drawn on the stage. is there anyway to get the stageWidth/Height before the first frame?
Here's the code I have.
Code:
package
{
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="250", height="250", backgroundColor="#000000")]
public class Main extends Sprite
{
public function Main ()
{
trace('width:', stage.stageWidth);
trace('height:', stage.stageHeight);
trace('________________________________________________');
init();
}
private function init ():void
{
trace('width:', stage.stageWidth, ' height:', stage.stageHeight);
this.addEventListener(Event.ENTER_FRAME, this.onenterframe)
}
private function onenterframe (ev:Event):void
{
trace('w:', stage.stageWidth, ' h:', stage.stageHeight);
}
}
}
I'm using Flex SDK 3.0.0.477. Thanks!
Retrieve The Stage.stageWidth Before Adding To DisplayList
Hi, there!
I'm trying to retrieve the stage.stageWidth and stage.stageHeight inside a component constructor before adding it to DisplayList.
And one of my components does not extends any of the DisplayObject classes, cause it is not drawn, but I still need to get the stage dimensions...
Any suggestions?
CaioToOn!
Stage.scaleMode And Stage.stageWidth
What am I missing here? According to the docs:
Quote:
When the value of the scaleMode property is not set to StageScaleMode.NO_SCALE, the stageWidth property represents the width of the SWF file as set during authoring in the Document Properties dialog box. This means that the value of the stageWidth property stays constant as you resize the Flash Player window. This property cannot be set.
So stick this in a new FLA
ActionScript Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, onResize);
function onResize(e:Event=null):void
{
trace( stage.stageWidth );
}
and the traces are of different values. According to the docs, this shouldn't be happening. What's going on? Did I miss something little?
|