Can't get stage from a constructor method. Why?
Hi,
I'm making a kind of image showcase, what has a fluid width and height, depending on browser window dimensions. Everything is okay, I have other kind of issue: in constructor function in this gallery class I can't use stage property, I have to get it from main class.
Why Flash treats me this way
and how I can avoid this currentStage variable?
Main code:
package dev {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.MovieClip;
import flash.events.Event;
import UI.BackgroundImageRotator;
public class Application extends Sprite {
public function Application():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
trace("Start.");
var BIR = new BackgroundImageRotator(stage);
stage.addChild(BIR);
}
}
}
BackgroundImageRotator class:
package UI {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
public class BackgroundImageRotator extends MovieClip {
protected var currentStage:Stage;
public function BackgroundImageRotator(currentStage:Stage):void {
this.x = 0;
this.y = 0;
this.currentStage = currentStage;
currentStage.addEventListener(Event.RESIZE, onStageResize);
}
protected function onStageResize(evt:Event):void {
trace(stage.stageWidth + ' ' + stage.stageHeight);
}
}
}