1 Reply Latest reply on Apr 27, 2007 6:26 PM by dwwangrui

    function property

    dwwangrui Level 1
      I am testing the function property .The actionscript3 reference said that
      You can define your own function properties by defining them outside your function body. Function properties can serve as quasi-static properties that allow you to save the state of a variable related to the function. For example, you may want to track the number of times a particular function is called. Such functionality could be useful if you are writing a game and want to track the number of times a user uses a specific command, although you could also use a static class property for this. The following code creates a function property outside the function declaration and increments the property each time the function is called:

      someFunction.counter = 0;

      function someFunction():void
      {
      someFunction.counter++;
      }

      someFunction();
      someFunction();
      trace(someFunction.counter); // 2

      quote:

      Text

      And i write my test code
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      someFunction.counter = 0;
      function someFunction():void
      {
      someFunction.counter++;
      }

      private function clickMe():void
      {
      someFunction();
      someFunction();
      content.text += someFunction.counter;
      }
      ]]>
      </mx:Script>
      <mx:TextArea id="content" text="" height="90" width="80%"/>
      <mx:Button label="try it" click="clickMe()"/>
      </mx:Application>
      quote:

      Text1

      Why the mxml can not be compiled ?