valetine
November 9th, 2008, 08:08 AM
Hi!
I'm trying to prevent my swf movie to scale and align top/left. This is the code that i put on my first frame movie:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT
Everything works fine. Now i'm trying to make the same but using a class like this:
viewer.as:
package classes{
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class viewer {
private var mcStage:Stage;
public function viewer():void {
init();
}
public function init():void {
mcStage.stage.scaleMode = StageScaleMode.NO_SCALE;
mcStage.stage.align = StageAlign.TOP_LEFT;
}
}
}
main.fla:
import classes.viewer;
var mystage:viewer = new viewer();
And i get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at classes::viewer/init()
at classes::viewer()
at viewer_fla::MainTimeline/frame1()
What's wrong?
I understand that i'm trying to access the stage before it's ready, but i can't understand why the code doesn't work when i put in a class but works when i put direct on the fla's first frame.
I hope somebody can explain me and show me the way to fix it. I was reading all night and i find many examples like this (Action Script 3: Resize SWF on Browser resize) (http://tush.wordpress.com/2007/06/25/action-script-3-resize-swf-on-browser-resize/) that works by creating an object and passing a movieclip as parameter... but in this step i don't want to relocate the movieclip (this will be my next step :krazy:), but now i just want to understand how the stage.scaleMode works inside a class...
as3 is kind of scary, i'm frustrated :hurt:.
Thanks!
I'm trying to prevent my swf movie to scale and align top/left. This is the code that i put on my first frame movie:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT
Everything works fine. Now i'm trying to make the same but using a class like this:
viewer.as:
package classes{
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class viewer {
private var mcStage:Stage;
public function viewer():void {
init();
}
public function init():void {
mcStage.stage.scaleMode = StageScaleMode.NO_SCALE;
mcStage.stage.align = StageAlign.TOP_LEFT;
}
}
}
main.fla:
import classes.viewer;
var mystage:viewer = new viewer();
And i get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at classes::viewer/init()
at classes::viewer()
at viewer_fla::MainTimeline/frame1()
What's wrong?
I understand that i'm trying to access the stage before it's ready, but i can't understand why the code doesn't work when i put in a class but works when i put direct on the fla's first frame.
I hope somebody can explain me and show me the way to fix it. I was reading all night and i find many examples like this (Action Script 3: Resize SWF on Browser resize) (http://tush.wordpress.com/2007/06/25/action-script-3-resize-swf-on-browser-resize/) that works by creating an object and passing a movieclip as parameter... but in this step i don't want to relocate the movieclip (this will be my next step :krazy:), but now i just want to understand how the stage.scaleMode works inside a class...
as3 is kind of scary, i'm frustrated :hurt:.
Thanks!