0 Replies Latest reply on Oct 29, 2010 5:40 AM by VeyronSA

    docWindow.open(); Noob Help

    VeyronSA

      Hi All,

       

      New with the Flash Builder and have done some google`ing to check if someone had done this before, but i`m getting nowhere. So i would like some assistance with a error i have.

       

      I have created 2 mxml Appliction files, one is called "start" and the other "DocumentWindow". Using Flex 3.5 SDK.

       

      I want the "start" application to run as a pre-loader for the application set in "DocumentsWindow", the "start" application get the latest update from the server where hosted, after about 10 seconds then the application "start" should open the "DocumentsWindow" application. But I`m getting nowhere and i see that the following code is a problem but cant solve it:

       

      docWindow.open();

       

      Here us the full app for "start.mxml"

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"

                                    layout="absolute"

                                    backgroundAlpha="0"     

                                    horizontalScrollPolicy="off"

                                    verticalScrollPolicy="off"

                                    showFlexChrome="false"

                                    width="401"

                                    height="201"

                                    preinitialize="init()"

                                    creationComplete="checkUpdate()">

           

           <mx:Image id="backgroundImage"

                       source="images/sp_bg.png"

                       top="0"

                       left="0"

                       width="400"

                       height="200"

                       />

           

           <mx:Script>

                <![CDATA[

                     

                     // Update Notice Function ////////////////////////////////////////////////

                     import air.update.ApplicationUpdaterUI;

                     import air.update.events.UpdateEvent;

                     import flash.events.ErrorEvent;

                     import mx.controls.Alert;

                     

                     private var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI();

                     

                     private function checkUpdate():void {

                          setApplicationVersion();

                          appUpdater.updateURL = "http://urltoserver/update.xml";

                          appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate);

                          appUpdater.addEventListener(ErrorEvent.ERROR, onError);

                          appUpdater.isCheckForUpdateVisible = false;

                          appUpdater.isFileUpdateVisible = false;

                          appUpdater.isInstallUpdateVisible = false;

                          appUpdater.initialize();

                     }

                     

                     private function onUpdate(event:UpdateEvent):void {

       

                          appUpdater.checkNow();

                     }

                     

                     private function onError(event:ErrorEvent):void {

                          Alert.show(event.toString());

                     }

                     

                     private function setApplicationVersion():void {

                          var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;

                          var ns:Namespace = appXML.namespace();

                          lblAppVersion.text = "" + appXML.ns::version;

                     }

                     // Launch Main.mxml Function /////////////////////////////////////////////

                     import myComponents.DocumentWindow;

                     private const LOAD_DELAY:int = 4;

                     private var timeElapsed:int = 0;

                     private var loadTimer:Timer;

                     

                     private var docWindow:DocumentWindow;

                     

                     private function init():void

                     {

                          // center the window on the screen

                          var screenBounds:Rectangle = Screen.mainScreen.bounds;

                          nativeWindow.x = (screenBounds.width - nativeWindow.width) / 2;

                          nativeWindow.y = (screenBounds.height - nativeWindow.height) / 2;

                          

                          // start the timer, which simulates a loading delay

                          loadTimer = new Timer(1000);

                          loadTimer.addEventListener(TimerEvent.TIMER, incrementTime);

                          loadTimer.start();

                          

                          updateStatus();

                     }

                     

                     private function incrementTime(event:TimerEvent):void

                     {

                          timeElapsed++;

                          

                          updateStatus();

                          

                          // if the loading delay has passed, stop the timer,

                          // close the splash screen, and open the document window

                          if ((LOAD_DELAY - timeElapsed) == 0)

                          {

                               loadTimer.stop();

                               loadTimer.removeEventListener(TimerEvent.TIMER, incrementTime);

                               loadTimer = null;

                               

                               nativeWindow.close();

                               

                               // open a new instance of the document window

                               docWindow = new DocumentWindow();

                               docWindow.open();

                          }

                     }

                     

                     private function updateStatus():void

                     {

                          var timeRemaining:uint = LOAD_DELAY - timeElapsed;

                          var timeRemainingMsg:String = timeRemaining.toString() + " second";

                          if (timeRemaining != 1) { timeRemainingMsg += "s"; }

                          timeRemainingMsg += " remaining.";

                     }

                ]]>

           </mx:Script>

           <mx:VBox x="6" y="156">

           </mx:VBox>

           <mx:Label id="lblAppVersion" color="#CCCCCC" width="150" x="5" y="157"/>

           <mx:Label x="2" y="174"  color="#CCCCCC" text="Copyright © 2010 Company"/>

       

      </mx:WindowedApplication>

       

      Here is the full code for "DocumentsWindow"

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

                                    width="1000"

                                    height="660">

           <mx:Label x="389" y="39" text="Document Window" width="112" height="20"/>

           

      </mx:WindowedApplication>

      Can someone please tell me what to do

       

      Thanks!

      VeyronSA