4 Replies Latest reply on Aug 6, 2007 4:51 PM by ntsiii

    SetVariable();

    Kai001
      I wanted to activate a function only when a variable called "refresh" equals "1". I've got the video with this code:
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="ac.send(); TimerExample();" layout="absolute" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="151">
      <mx:Script>
      <![CDATA[
      import flash.events.*;
      import mx.events.*;
      import mx.controls.*;
      import flash.utils.Timer;

      private function clickEvt(event:Event):void {
      var theData:String = ""
      if (event.currentTarget.selectedItem.@data) {
      theData = event.currentTarget.selectedItem.@data;
      }
      fscommand("Section", theData);
      }

      public function TimerExample() {
      var myTimer:Timer = new Timer(1000, 0);
      myTimer.addEventListener("timer", timerHandler);
      myTimer.start();
      Alert.show("Timer Started!");
      }

      public function timerHandler(event:TimerEvent):void {
      var refresh:String = this.loaderInfo.parameters.refresh;
      Alert.show("Activated...");
      if(refresh=="1"){
      Alert.show("Ran...");
      ac.send();
      refresh="0";
      }
      }
      ]]>
      </mx:Script>
      <mx:HTTPService id="ac" url=" http://www.aspergercolony.com/AnimalCrossingMag/GuideFolders.php" resultFormat="xml" useProxy="false" showBusyCursor="true"/>
      <mx:Tree width="100%" height="100%" dataProvider="{ac.lastResult}" labelField="@label" click="clickEvt(event);"/>
      </mx:Application>

      This is my HTML which I've copied directly from sites that it works on:
      http://pastebin.ca/647195

      The problem is it never seems to notice that "Refresh" equals "1". When I manually set it by adding
      under the <embed tag "FlashVars="refresh=1"" it works. So is it my JS?

      Any help tis GREATLY apprecaited!! :D
        • 1. Re: SetVariable();
          Michael Kraft
          It looks like you only have to states for refresh: 1 and 0. So why don't you use a boolean?

          example:

          private var myRefresh:boolean = true;

          if (myRefresh==true){
          doTheStuff();
          myRefresh=false;
          }
          • 2. Re: SetVariable();
            chris.huston.t10 Level 3
            The fscommand has been replaced with the ExternalInterface API. Here is a simple example:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Script>
            <![CDATA[
            import flash.external.ExternalInterface;
            import mx.controls.Alert;

            private function getRefresh():void {
            var jsResult:String;
            if (ExternalInterface.available) {
            jsResult = ExternalInterface.call("getRefresh");
            Alert.show(jsResult);
            } else {
            Alert.show("Wrapper not available");
            }
            }

            ]]>
            </mx:Script>
            <mx:Button x="60" y="40" label="Button" click="getRefresh()"/>
            </mx:Application>

            Then in your html you would add:

            <SCRIPT LANGUAGE="JavaScript">
            function getRefresh() {
            return "1";
            }
            </SCRIPT>

            The above will show the Alert of 1. However, looking at your example, I am not sure why you need to call a JS function.

            Vygo
            • 3. Re: SetVariable();
              Kai001 Level 1
              Thanks for the help! :D

              ( Well I needed this tree to refresh whenever someone filled out a form in another frame. )
              • 4. Re: SetVariable();
                ntsiii Level 3
                Also, use resultFormat="e4x" instead of resultFormat="xml". "xml" is the old-fashioned AS2 xml object, now called XMLNode. It lacks sooo many of the great features of the new e4x XML class.

                Tracy