Ok, so I’m not sure I’m going about this the right way so I could use some suggestions. I’m trying to create a class that will resize and move navigation items based on the size of the browser, so a website will work even if a user stretches the browser screen around. I have done this easily before as a function within a class, but now I want it to be a class of its own that gets instantiated once, then clips can be registered to it throughout the play of the site.
I created a class that gets passed an object, along with its effected property (ie. ‘x’, or ‘width’) and end value, which then adds it to an array which keeps track of all the registered objects, then adjusts each of their specific properties when the stage is resized.
It works fine for passing simple values, such as 10, but more often I want to pass much more complex values which resize an image based on the size and height/width ratio of the stage in comparison to the height/width ratio of that image. The problem is that the values cannot actually be read until they reach this class (for instance I couldn’t register an object with an end value such as stage.stageHeight-100 because stageHeight would be read as the height of the stage at the time the object was registered with the class and would remain a static value).
The only thing I can think of that would work would be to pass a string value, then parse it on the other side, but I don’t know how to do this. I tried a couple of string calculator classes that people have created, but couldn’t get them working.
Does anybody have any ideas? Your help is appreciated very much!!!
Here is the class I have created below:
public class StageListener
{
private var objectList:Array = new Array();
private var i:uint = 0;
public function register($object:*, $vars:Object):void {
objectList*:Object = new Object();
objectList*.obj = $object;
objectList*.prty = $vars.$prty;
objectList*.val = $vars.$val;
i++;
}
public function StageListener():void
{
Glo.bal.rootStage.align=StageAlign.TOP_LEFT;
Glo.bal.rootStage.scaleMode=StageScaleMode.NO_SCALE;
Glo.bal.rootStage.addEventListener(Event.RESIZE, resizeHandler);
}
private function resizeHandler(event:Event):void
{
for(var j:* in objectList) {
objectList[j].obj[objectList[j].prty] = objectList[j].val;
}
}
}
Objects are registed like this:
StageListenerInstance.register(mySprite, {$prty:"x", $val:"stage.stageWidth-200"})