Re: [swiz-framework] Need to ensure that code runs prior to any Swiz initialization

26 views
Skip to first unread message

Brian Kotek

unread,
Nov 5, 2012, 12:02:39 PM11/5/12
to swiz-fr...@googlegroups.com
Correct, Swiz does all of it's processing at preinitialize. Even if you force something to run earlier (by setting the event priority higher, for example), if it's an async call the rest of the Swiz bootstrapping is going to run before the async call returns. 

You might look at using or adapting the solution that's offered in the SwizConfigValueLoader extension: https://github.com/swiz/swiz-extensions/tree/master/SwizConfigValueLoader



On Mon, Nov 5, 2012 at 11:42 AM, Christian Witte <christi...@gmail.com> wrote:
I have code in my application that must run prior to Swiz initializing any Beans. I have placed the code in a function that is triggered on the Application preinitialize event, but Swiz starts to initialize beans before that code executes. The relevant portions of my application's mxml file is as follows:

The "preinit" code is loading server config information from an xml file -- all of my beans depend on that information being there. I've set breakpoints on the first line of both preinit() and configureChannels(), and I get an error from one of my bean classes before either breakpoint trips.

Any help would be greatly appreciated -- thank you!

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:view="org.vertex.view.*"
               xmlns:swiz="http://swiz.swizframework.org"
               xmlns:config="org.vertex.config.*"
               minHeight="0" minWidth="0"
               height="100%" width="100%"
               skinClass="org.vertex.skins.ApplicationContainerSkin"
               xmlns:form="org.vertex.form.*"
               xmlns:editComponents="org.vertex.editComponents.*"
               preinitialize="preinit(event)">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayList;
            import mx.controls.Alert;
            import mx.controls.menuClasses.MenuBarItem;
            import mx.core.FlexGlobals;
            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;
            import mx.messaging.ChannelSet;
            import mx.messaging.channels.RTMPChannel;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;
            import mx.states.State;
           
            import org.vertex.AppModel;
           
            [Inject(bind="true",twoWay="true")]
            [Bindable]
            public var appModel:AppModel;
           
            public var cs:ChannelSet;
           
            public function genericFault(fe:FaultEvent):void
            {
                //Alert.show(fe.message.toString());
                var popup:DiagnosticView = new DiagnosticView();
                popup.errorString = fe.message.toString();
                PopUpManager.addPopUp(popup, FlexGlobals.topLevelApplication.contentGroup, true);
                PopUpManager.centerPopUp(popup);
            }
            protected function preinit(event:FlexEvent):void
            {
                var configSrv:HTTPService = new HTTPService();
                configSrv.url="channels.xml";
                configSrv.resultFormat="e4x";
                configSrv.addEventListener(ResultEvent.RESULT, configureChannels);
                configSrv.send();
            }
           
            public function configureChannels(event:ResultEvent):void {
               
                var xml:XML = event.result as XML;
                xml.channel.(trace(@id));
                var centralRTMP:String = "" + xml..channel.(@id=="my-rtmp").@endpoint;
                var localRTMP:String="" + xml..channel.(@id=="local-rtmp").@endpoint;
                if(localRTMP == "" || localRTMP == "") {
                    Alert.show("Channel configuration error");
                }
                else {
                    cs = new ChannelSet();
                    cs.addChannel(new RTMPChannel("my-rtmp", centralRTMP));
                    cs.addChannel(new RTMPChannel("local-rtmp", localRTMP));
                }
            }
           
        ]]>
    </fx:Script>
    <fx:Declarations>
        <swiz:Swiz>
            <swiz:beanProviders>
                <config:Beans/>
            </swiz:beanProviders>
            <swiz:config>
                <swiz:SwizConfig eventPackages="org.vertex.event"
                                 viewPackages="org.vertex.view,org.vertex.presentationmodel,org.vertex.form,org.vertex.editComponents"
                                 defaultFaultHandler="{genericFault}"/>
            </swiz:config>
        </swiz:Swiz>
    </fx:Declarations>

--
You received this message because you are subscribed to the Google Groups "Swiz Framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/pOrDu4ZSOfsJ.
To post to this group, send email to swiz-fr...@googlegroups.com.
To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swiz-framework?hl=en.

Christian Witte

unread,
Nov 5, 2012, 4:46:07 PM11/5/12
to swiz-fr...@googlegroups.com
Thank you for the reply! This solution worked for me.
Reply all
Reply to author
Forward
0 new messages