Yeah, in AS3 your main class should extend Sprite (or a child of Sprite) in order to (a) get on the DisplayList of the stage and (b) receive keyboard/mouse focus. You could also inherit from MovieClip (like AS2).
The root is not defined right away because you're checking for it in the constructor. To be honest, that had confounded me right up until the point that I read your e-mail. Now I think I understand what's going on (perhaps an Adobe engineer can confirm or deny): In the class constructor, root/stage/etc. are not defined because your object has not yet been added to any DisplayList. This is a side-effect of the new feature in AS3's display architecture that allows you to have off-stage DisplayObjects (which is a good thing). If you imagine what the Flash Player is doing (pseudo-code, I'm sure the player is not using AS3): var mainInteractiveObject:flash.display.InteractiveObject = new YourMainClass(); stage.addChild(mainInteractiveObject); So, you see, when the constructor is called your object is not yet a child of the stage, thus the class member "stage" and "root" are meaningless. Instead of the timer event, you should add an event listener for the "addedToStage" event (Event.ADDED_TO_STAGE). You will then have a valid stage property set. Troy. On 2/22/07, {reduxdj} <[EMAIL PROTECTED]> wrote:
I didn't realize two things trying to get at flashvars in a non-timeline swf compiling with SDK. 1. To get the LoaderInfo apparently you have to extend Sprite (er, i think) 2. The root is not defined right away... so I am doing a cheesy timer event because you can't add a listener to the loaderInfo there's probably a better way... this seems quite hackish, i guess I could make it loop the timer object till it's defined etc. P package com.me.views { import flash.display.Sprite; import flash.display.*; import com.me.data.PictureProvider; import flash.events.Event; import flash.display.LoaderInfo; import flash.events.TimerEvent; import flash.utils.Timer; public class AbstractSlideView extends Sprite { protected var _data:PictureProvider; public function AbstractSlideView() { var timer:Timer = new Timer(1000,1); timer.addEventListener(TimerEvent.TIMER, installVars); timer.start(); } public function installVars(e:TimerEvent){ var keyStr:String; var valueStr:String; trace (this.root); try { var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; trace (paramObj.toString()); for (keyStr in paramObj) { valueStr = String(paramObj[keyStr]); trace ("folderid="+String(paramObj["folderid"])) trace("\t" + keyStr + ":\t" + valueStr + "\n"); trace ("folderid="+paramObj.folderid); } _data = new PictureProvider(paramObj); _data.addEventListener(Event.CHANGE,draw); }catch (error:Error){ trace (error); } } protected function draw(event:Event):void{ } } }