6 Replies Latest reply on Jul 22, 2010 10:30 AM by Tuchel22

    Problem with NETWORK_CHANGE

    Tuchel22

      I used this code in Flash CS4 and it worked. Now using Flash Builder 4.0.1, AIR 2.0.2 on a Mac OS 10.6.4 and I get an error.

       

      NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChangeHandler);

       

       

      private function onNetworkChangeHandler(event:Event):void

      {

      Alert.show("Network Event Triggered");

      }

       

      Description Resource Path Location Type

      1120: Access of undefined property onNetworkChangeHandler.

        • 1. Re: Problem with NETWORK_CHANGE
          Anirudh Sasikumar Adobe Employee

          From the error, it looks like your event handler function is not known at the point where you are calling addEventListener.

           

          Can you post your complete file (portions may be stripped out, but what I want to see is your package/class structure at the time you are registering the listener and where your listener is defined).

           

          Thanks,

          Anirudh

          • 2. Re: Problem with NETWORK_CHANGE
            Tuchel22 Level 1

            Here is most of the code.

             

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

            <!-- KioskTest03 horizontal, MacNumbers and Weather -->

            <s:WindowedApplication 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:soliant="com.soliantconsulting.flexfm.simple.*"

               height.ImageScreen="770" height.SplashScreen="644" width.ImageScreen="1274" backgroundColor.ImageScreen="#5068B6"

               creationComplete="doFind(), getData()"  width.SplashScreen="932" showStatusBar="false" backgroundColor.SplashScreen="#F7D6D6"

               xmlns:macnumbers="services.macnumbers.*" xmlns:myweather="services.myweather.*"

               width.VideoScreen="1274" height.VideoScreen="770" backgroundColor.VideoScreen="#5068B6">

             

            <s:states>

            <s:State name="SplashScreen" /> <!-- Splash screen -->

            <s:State name="ImageScreen" /> <!-- Image screen -->

            <s:State name="VideoScreen" /> <!-- Video screen -->

            </s:states>

             

            <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

            <fx:Style source="KioskStyle.css"/>

             

            <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

            <fx:Script>

            <![CDATA[

            //  imports ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            import air.net.*;

            import flash.desktop.*;

            import flash.display.*;

            import flash.events.Event;

            import flash.net.*;

            import mx.collections.ArrayCollection;

            import mx.controls.Alert;

            import mx.events.FlexEvent;

             

            [Bindable]

            public var kioskVersion:String = "07/13/10  3.4(015)";

             

            private const IMAGE_DELAY:int = 15;

            private var imageElapsed:int = 0;

            private const WEATHER_DELAY:int = 15;

            private var weatherElapsed:int = 0;

            private const SPLASH_DELAY:int = 3;

            private var timeElapsed:int = 0;

            private var loadTimer:Timer;

             

            [Bindable]

            public var myDate:Date = new Date();

             

            public var cc:String = "*";

            public var key:String = "385d19159651413a";

            public var link:String = "xoap";

            public var par:String = "1070880953";

            public var unit:String = "us";

             

            public function doFind():void {

            findRequest.execute();

            var screenBounds:Rectangle = Screen.mainScreen.bounds;

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

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

            loadTimer = new Timer(1000);

            loadTimer.addEventListener(TimerEvent.TIMER, incrementTime);

            loadTimer.start();

            updateStatus();

            }

             

            public var r:int = 1;

            [Bindable]

            public var i:int = 57; // TEMPORARY set to 57 for short run, should be 0 ******

             

            private function incrementTime(event:TimerEvent):void {

            timeElapsed++;

            weatherElapsed++;

            imageElapsed++;

            updateStatus();

            if ((SPLASH_DELAY - timeElapsed) == 0) {

            currentState="ImageScreen";

            nativeWindow.maximize();

            nativeWindow.stage.displayState = StageDisplayState.FULL_SCREEN;

             

            var startDate:Date = new Date();

            var startstat:String=startDate+", "+" starting test "+"\n";

            writeLog(startstat);

            }

            if ((IMAGE_DELAY - imageElapsed) == 0) {

            var recCount:int = myCol.length;

            if (i < (recCount - 1)) {i = i + 1}

            else {i = 57} // TEMPORARY set to 57 for short run, should be 0 ******

             

            var imagepath:String = myCol.getItemAt(i).image_file_path_kiosk;

            if (imagepath.substr(-3,3) == "flv") {

            currentState="VideoScreen";

            nativeWindow.maximize();

            nativeWindow.stage.displayState = StageDisplayState.FULL_SCREEN;

            }

            else {currentState="ImageScreen"}

             

            fadeout.play();

            imageElapsed=0;

             

            var ourDate:Date = new Date();

            var mystat:String=ourDate+", "+myCol.getItemAt(i).image_file_path_kiosk+"\n";

            writeLog(mystat);

            }

            if ((WEATHER_DELAY - weatherElapsed) == 0) {

            myDate = new Date();

            if (r == 1) {

            myR3dateTo.play();

            myR3tempTo.play();

            r = 0;

            }

            else {

            myR3tempFrom.play();

            myR3dateFrom.play();

            r = 1

            }

            weatherElapsed=0;

            }

            }

             

            private function updateStatus():void {

            var timeRemaining:uint = SPLASH_DELAY - timeElapsed;

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

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

            timeRemainingMsg += " remaining.";

             

            loadStatusMessage.text = "initializing... " + timeRemainingMsg;

            }

             

            protected function getData():void {

            getDataResult.token = macNumbers.getData();

            }

             

            protected function cityTemp_creationCompleteHandler(event:FlexEvent):void {

            Operation1Result.token = myweather.Operation1(cc, key, link, par, unit);

            }

             

            NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE, onNetworkChangeHandler);

             

            private function onNetworkChangeHandler(event:Event):void

            {

            Alert.show("Network Event Triggered");

            }

             

            private function writeLog(stat:String):void {

            var file:File=File.desktopDirectory.resolvePath("KioskLog.txt");

            var fileStream:FileStream=new FileStream  ;

            fileStream.open(file,FileMode.APPEND);

            fileStream.writeMultiByte(stat,File.systemCharset);

            fileStream.close();

            }

            ]]>

            </fx:Script>

             

            <fx:Declarations>

            <!-- FlexFM - build the server ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

            <soliant:FMServer id="myServer" host="www.cmp.ucr.edu"/>

            <soliant:FMRequest id="findRequest" server="{myServer}" db="scoop" layout="onlineFlashCheck" query="-findall" />

             

            <mx:ArrayCollection id="myCol" source="{findRequest.lastResult.records}"/>

             

            <mx:DateFormatter id="DateDisplay" formatString="EEEE, MMMM, DD, YYYY L:NN A" />

             

            <!-- Effects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

            <s:Fade id="fadeout" target="{kioskImage}" duration="4000" alphaFrom="0.0" alphaTo="1.0" />

            <s:Move3D id="myMove" target="{myTimeNdate}" zBy="3000" duration="2000"/>

            <s:Resize id="myResize" target="{myTimeNdate}" widthBy="-3000" />

            <s:Rotate id="myRotate" target="{myTimeNdate}" autoCenterTransform="true" angleBy="90"/>

            <s:Rotate3D id="myR3dateTo" target="{myTimeNdate}" autoCenterTransform="true" angleXFrom="0" angleXTo="90" duration="3000"/>

            <s:Rotate3D id="myR3tempTo" target="{cityTemp}" autoCenterTransform="true" angleXFrom="90" angleXTo="0" duration="7000"/>

            <s:Rotate3D id="myR3dateFrom" target="{myTimeNdate}" autoCenterTransform="true" angleXFrom="90" angleXTo="0" duration="7000"/>

            <s:Rotate3D id="myR3tempFrom" target="{cityTemp}" autoCenterTransform="true" angleXFrom="0" angleXTo="90" duration="3000"/>

             

            <!-- Data Services ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

            <s:CallResponder id="getDataResult"/>

            <macnumbers:MacNumbers id="macNumbers" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

            <s:CallResponder id="Operation1Result"/>

            <myweather:Myweather id="myweather" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

             

            </fx:Declarations>

            • 3. Re: Problem with NETWORK_CHANGE
              Tuchel22 Level 1

              Thanks for your help.

               

              Here is the mxml file, all of our code is in it, if I comment out the NativeApplication line the rest of the program runs.

              • 4. Re: Problem with NETWORK_CHANGE
                Anirudh Sasikumar Adobe Employee

                Take the NativeApplication.nativeApplication.addEventListener line and put it in a method and call that method when creationComplete fires.

                 

                In Flex, you cannot simply put a stray line of code not attached to a method or a field. (If you put code in an MXML attribute, the compiler wraps it in a method behind the scenes.

                1 person found this helpful
                • 5. Re: Problem with NETWORK_CHANGE
                  Tuchel22 Level 1

                  Thanks for the quick replay.

                  • 6. Re: Problem with NETWORK_CHANGE
                    Tuchel22 Level 1

                    Moved the "NativeApplication.nativeApplication.addEventListener......" into my creationComplete function and it works fine.