[flexcoders] Re: Two questions: Nested applications styles colllisions, flashvars injection
For anyone interested, I was able to get this to work normally when building or with a loader passing flashvars: package { import flash.display.Loader; import mx.core.Application; public class MyApplication extends Application { public function MyApplication() { super(); } override public function get parameters():Object { if(systemManager.document.parent.parent is Loader) return systemManager.document.parent.parent.loaderInfo.parameters; else return super.parameters; } } } --- In flexcoders@yahoogroups.com, "Alex Harui" wrote: > > I still think I'd override the parameters getter in Application. > > > > Class MyApp extends Application > > { > > Override public function get paramters():Object > > { > > Return systemManager.parent.loaderInfo.parameters. > > } > > } > > > > > > From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On > Behalf Of mydarkspoon > Sent: Monday, June 02, 2008 8:21 AM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Re: Two questions: Nested applications styles > colllisions, flashvars injection > > > > The _firstTime var declaration was dropped out of the code. > it's: > private static var _firstTime:Boolean = true; > > Actually, the reason I used the first time is quite weird, if I set > the dispatchEventHook to null after getting the first preinitialize > event, it keeps calling it... > However, if I set it to ther fucntion it will call the other function. > > Thanks, > > Almog Kurtser, > http://www.kaltura.com/ <http://www.kaltura.com/> > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > , "mydarkspoon" wrote: > > > > Hi Alex, > > thanks for your reply. > > I guess you're right about the styles, since we use modal window to > > open the loaded swf, we simply unloaded the main app styles before > > loading the 2nd app. > > Then, when the user is done with the loaded swf, we called it's > > deactivate() method which unloads its styles and the main app reloads > > its styles. > > > > About the flashvars, I made it work, in a very hacky way, but I can't > > think of anything else. > > Basically, the solution is to catch the right moment to inject data to > > the application.parameters, which is between when the application gets > > a copy of the SystemManager.parameters and the tyime when the > > application dispatces a "preinitialize" event, which is the time for > > the app to start kicking. > > The only way I found to catch this moment was to use the event > > UIComponent.dispatchEventHook and check for the first "preinitialize" > > event. > > I had 2 problems with that: > > 1. I use actionscript only application for the wrapper, otherwise it > > will make no sense to use a wrapper - that can be solved by copying > > the mx_internal to access the UIComponent.dispatchEventHook and using > > ApplicationDomain.getDefinition() > > 2. The UIComponent class definition is only avialable through > > ApplicationDomain.getDefinition() at the SystemManager 2nd frame > > So at first, I thought I could simply add an event listener to the > > enterFrame, but then I found out, that the enterFrame is always > > dispatched after the frameScript function, which in some cases can be > > too late, because the application can get initialized and disapcth the > > preinitialize before the first enterFrame event for frame 2 is > dispacthed. > > So, to overcome these timing issues I had to override the call to the > > SystemManager.docFrameHandler, by passing my own frameScript function > > where I first acquire the UICompoennt class definition to use its > > dispatch hook, and only then call the SystemManager.docFrameHandler > > "manually" > > > > Enough bubbling, here is the code, it's hacky, I'm aware of the risk > > of using the mx_internal, but currently it works, so here it is: > > > > package { > > import flash.display.Loader; > > import flash.display.MovieClip; > > import flash.display.StageAlign; > > import flash.display.StageScaleMode; > > import flash.events.Event; > > import flash.net.URLRequest; > > > > import mx.managers.SystemManager; SystemManager
RE: [flexcoders] Re: Two questions: Nested applications styles colllisions, flashvars injection
I still think I'd override the parameters getter in Application. Class MyApp extends Application { Override public function get paramters():Object { Return systemManager.parent.loaderInfo.parameters. } } From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of mydarkspoon Sent: Monday, June 02, 2008 8:21 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Two questions: Nested applications styles colllisions, flashvars injection The _firstTime var declaration was dropped out of the code. it's: private static var _firstTime:Boolean = true; Actually, the reason I used the first time is quite weird, if I set the dispatchEventHook to null after getting the first preinitialize event, it keeps calling it... However, if I set it to ther fucntion it will call the other function. Thanks, Almog Kurtser, http://www.kaltura.com/ <http://www.kaltura.com/> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "mydarkspoon" <[EMAIL PROTECTED]> wrote: > > Hi Alex, > thanks for your reply. > I guess you're right about the styles, since we use modal window to > open the loaded swf, we simply unloaded the main app styles before > loading the 2nd app. > Then, when the user is done with the loaded swf, we called it's > deactivate() method which unloads its styles and the main app reloads > its styles. > > About the flashvars, I made it work, in a very hacky way, but I can't > think of anything else. > Basically, the solution is to catch the right moment to inject data to > the application.parameters, which is between when the application gets > a copy of the SystemManager.parameters and the tyime when the > application dispatces a "preinitialize" event, which is the time for > the app to start kicking. > The only way I found to catch this moment was to use the event > UIComponent.dispatchEventHook and check for the first "preinitialize" > event. > I had 2 problems with that: > 1. I use actionscript only application for the wrapper, otherwise it > will make no sense to use a wrapper - that can be solved by copying > the mx_internal to access the UIComponent.dispatchEventHook and using > ApplicationDomain.getDefinition() > 2. The UIComponent class definition is only avialable through > ApplicationDomain.getDefinition() at the SystemManager 2nd frame > So at first, I thought I could simply add an event listener to the > enterFrame, but then I found out, that the enterFrame is always > dispatched after the frameScript function, which in some cases can be > too late, because the application can get initialized and disapcth the > preinitialize before the first enterFrame event for frame 2 is dispacthed. > So, to overcome these timing issues I had to override the call to the > SystemManager.docFrameHandler, by passing my own frameScript function > where I first acquire the UICompoennt class definition to use its > dispatch hook, and only then call the SystemManager.docFrameHandler > "manually" > > Enough bubbling, here is the code, it's hacky, I'm aware of the risk > of using the mx_internal, but currently it works, so here it is: > > package { > import flash.display.Loader; > import flash.display.MovieClip; > import flash.display.StageAlign; > import flash.display.StageScaleMode; > import flash.events.Event; > import flash.net.URLRequest; > > import mx.managers.SystemManager; SystemManager; > import mx.core.mx_internal; > import mx.core.EventPriority; > //import mx.core.mx_internal; > > public class SWFWrapper extends MovieClip > { > //import mx.core.mx_internal; > private var _loader:Loader = new Loader; > private var _systemManager:MovieClip; > private var _classUiComponent:Class; > > use namespace mx_internal; > > public function SWFWrapper() > { > stage.scaleMode = StageScaleMode.NO_SCALE; > stage.align = StageAlign.TOP_LEFT; > _loader.contentLoaderInfo.addEventListener(Event.INIT, > loaderCompleteHandler, false, EventPriority.DEFAULT_HANDLER); > _loader.load(new URLRequest("Loadee.swf")); > this.addChild(_loader); > } > > private function loaderCompleteHandler(completeEvent:Event):void > { > _systemManager = _loader.content as MovieClip; > _systemManager.addFrameScript(1, docFrameHandler); > } > > private function docFrameHandler(e:Event = null):void > { > _classUiComponent = > _systemManager.loaderInfo.applicationDomain.getDefinition("mx.core.UICom ponent") > as Class; > _classUiComponent.mx_internal::["dispatchEventHook"] = myEventHook; > _systemManager.mx_internal::["docFrameHandler"](); > } > > private fun
[flexcoders] Re: Two questions: Nested applications styles colllisions, flashvars injection
The _firstTime var declaration was dropped out of the code. it's: private static var _firstTime:Boolean = true; Actually, the reason I used the first time is quite weird, if I set the dispatchEventHook to null after getting the first preinitialize event, it keeps calling it... However, if I set it to ther fucntion it will call the other function. Thanks, Almog Kurtser, http://www.kaltura.com/ --- In flexcoders@yahoogroups.com, "mydarkspoon" <[EMAIL PROTECTED]> wrote: > > Hi Alex, > thanks for your reply. > I guess you're right about the styles, since we use modal window to > open the loaded swf, we simply unloaded the main app styles before > loading the 2nd app. > Then, when the user is done with the loaded swf, we called it's > deactivate() method which unloads its styles and the main app reloads > its styles. > > About the flashvars, I made it work, in a very hacky way, but I can't > think of anything else. > Basically, the solution is to catch the right moment to inject data to > the application.parameters, which is between when the application gets > a copy of the SystemManager.parameters and the tyime when the > application dispatces a "preinitialize" event, which is the time for > the app to start kicking. > The only way I found to catch this moment was to use the event > UIComponent.dispatchEventHook and check for the first "preinitialize" > event. > I had 2 problems with that: > 1. I use actionscript only application for the wrapper, otherwise it > will make no sense to use a wrapper - that can be solved by copying > the mx_internal to access the UIComponent.dispatchEventHook and using > ApplicationDomain.getDefinition() > 2. The UIComponent class definition is only avialable through > ApplicationDomain.getDefinition() at the SystemManager 2nd frame > So at first, I thought I could simply add an event listener to the > enterFrame, but then I found out, that the enterFrame is always > dispatched after the frameScript function, which in some cases can be > too late, because the application can get initialized and disapcth the > preinitialize before the first enterFrame event for frame 2 is dispacthed. > So, to overcome these timing issues I had to override the call to the > SystemManager.docFrameHandler, by passing my own frameScript function > where I first acquire the UICompoennt class definition to use its > dispatch hook, and only then call the SystemManager.docFrameHandler > "manually" > > Enough bubbling, here is the code, it's hacky, I'm aware of the risk > of using the mx_internal, but currently it works, so here it is: > > package { > import flash.display.Loader; > import flash.display.MovieClip; > import flash.display.StageAlign; > import flash.display.StageScaleMode; > import flash.events.Event; > import flash.net.URLRequest; > > import mx.managers.SystemManager; SystemManager; > import mx.core.mx_internal; > import mx.core.EventPriority; > //import mx.core.mx_internal; > > public class SWFWrapper extends MovieClip > { > //import mx.core.mx_internal; > private var _loader:Loader = new Loader; > private var _systemManager:MovieClip; > private var _classUiComponent:Class; > > use namespace mx_internal; > > public function SWFWrapper() > { > stage.scaleMode = StageScaleMode.NO_SCALE; > stage.align = StageAlign.TOP_LEFT; > _loader.contentLoaderInfo.addEventListener(Event.INIT, > loaderCompleteHandler, false, EventPriority.DEFAULT_HANDLER); > _loader.load(new URLRequest("Loadee.swf")); > this.addChild(_loader); > } > > private function loaderCompleteHandler(completeEvent:Event):void > { > _systemManager = _loader.content as MovieClip; > _systemManager.addFrameScript(1, docFrameHandler); > } > > private function docFrameHandler(e:Event = null):void > { > _classUiComponent = > _systemManager.loaderInfo.applicationDomain.getDefinition("mx.core.UIComponent") > as Class; > _classUiComponent.mx_internal::["dispatchEventHook"] = > myEventHook; > _systemManager.mx_internal::["docFrameHandler"](); > } > > private function myEventHook(event:Event, uic:Object):void > { > if (event.type == "preinitialize" && _firstTime) > { > _firstTime = false; > > _systemManager["application"]["parameters"]["message"] = "Great > success!"; > } > } > } > } > > --- In flexcoders@yahoogroups.com, "Alex Harui" wrote: > > > > There is no good way to have a
[flexcoders] Re: Two questions: Nested applications styles colllisions, flashvars injection
Hi Alex, thanks for your reply. I guess you're right about the styles, since we use modal window to open the loaded swf, we simply unloaded the main app styles before loading the 2nd app. Then, when the user is done with the loaded swf, we called it's deactivate() method which unloads its styles and the main app reloads its styles. About the flashvars, I made it work, in a very hacky way, but I can't think of anything else. Basically, the solution is to catch the right moment to inject data to the application.parameters, which is between when the application gets a copy of the SystemManager.parameters and the tyime when the application dispatces a "preinitialize" event, which is the time for the app to start kicking. The only way I found to catch this moment was to use the event UIComponent.dispatchEventHook and check for the first "preinitialize" event. I had 2 problems with that: 1. I use actionscript only application for the wrapper, otherwise it will make no sense to use a wrapper - that can be solved by copying the mx_internal to access the UIComponent.dispatchEventHook and using ApplicationDomain.getDefinition() 2. The UIComponent class definition is only avialable through ApplicationDomain.getDefinition() at the SystemManager 2nd frame So at first, I thought I could simply add an event listener to the enterFrame, but then I found out, that the enterFrame is always dispatched after the frameScript function, which in some cases can be too late, because the application can get initialized and disapcth the preinitialize before the first enterFrame event for frame 2 is dispacthed. So, to overcome these timing issues I had to override the call to the SystemManager.docFrameHandler, by passing my own frameScript function where I first acquire the UICompoennt class definition to use its dispatch hook, and only then call the SystemManager.docFrameHandler "manually" Enough bubbling, here is the code, it's hacky, I'm aware of the risk of using the mx_internal, but currently it works, so here it is: package { import flash.display.Loader; import flash.display.MovieClip; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.net.URLRequest; import mx.managers.SystemManager; SystemManager; import mx.core.mx_internal; import mx.core.EventPriority; //import mx.core.mx_internal; public class SWFWrapper extends MovieClip { //import mx.core.mx_internal; private var _loader:Loader = new Loader; private var _systemManager:MovieClip; private var _classUiComponent:Class; use namespace mx_internal; public function SWFWrapper() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; _loader.contentLoaderInfo.addEventListener(Event.INIT, loaderCompleteHandler, false, EventPriority.DEFAULT_HANDLER); _loader.load(new URLRequest("Loadee.swf")); this.addChild(_loader); } private function loaderCompleteHandler(completeEvent:Event):void { _systemManager = _loader.content as MovieClip; _systemManager.addFrameScript(1, docFrameHandler); } private function docFrameHandler(e:Event = null):void { _classUiComponent = _systemManager.loaderInfo.applicationDomain.getDefinition("mx.core.UIComponent") as Class; _classUiComponent.mx_internal::["dispatchEventHook"] = myEventHook; _systemManager.mx_internal::["docFrameHandler"](); } private function myEventHook(event:Event, uic:Object):void { if (event.type == "preinitialize" && _firstTime) { _firstTime = false; _systemManager["application"]["parameters"]["message"] = "Great success!"; } } } } --- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote: > > There is no good way to have a loaded SWF keep its own styles. There > might be in 3.x later this year. > > > > Since you own both SWFs, I'd simply have a handshake between the loader > and the loaded app. Sublcass App, override its parameters property and > have it query the loading Apps loaderInfo.parameters. > > > > > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of mydarkspoon > Sent: Saturday, May 31, 2008 4:22 AM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Two questions: Nested applications styles > colllisions,