Say I've got a utility class in which I would like to access the stage (in order to get the frameRate).
I don't particularly want to force the user to pass in the stage to each method or set a static property on my class before using it.
Is there any way to get ahold of the stage without it being passed in? All I need is the frameRate!
set the framerate as a public static variable or public constant in your main document class (or where ever else a reference to the stage is available) then call that static variable from your utility class:
Document Class
package
{
//Imports
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
//Class
[SWF(width = "1000", height = "500", BackgroundColor = "0x555555")]
public class DocumentClass extends Sprite
{
//Static Variables
public static var FRAME_RATE:uint;
//Constructor
public function DocumentClass()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = FRAME_RATE = 60;
//...
}
}
}
Utility Class
package
{
//Imports
import flash.events.EventDispatcher;
//Class
public class UtilityClass extends EventDispatcher
{
//Constructor
public function UtilityClass()
{
trace("SWF Frame Rate: " + DocumentClass.FRAME_RATE);
}
}
}
[EDIT]:
in your case where you don't have direct access to the stage you could have your users pass the stage.frameRate
value to the constructor of your utility class, but i'm sure you will agree this approach isn't very elegant. i think that your idea to measure the intervals between ENTER_FRAME events is the best solution.