5 Replies Latest reply on Jun 14, 2009 8:44 PM by Michael Borbor

    Sending a variable from a class to a parent

    SiHoop Level 1

      How can I send a value to a variable in a parent? Here's my main file: It includes an array, myArray, that I want to change from several instances of the class:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
        <mx:Script>
         <![CDATA[
      private var myArray:Array=[]
      private var class1: MyClass
      private function init():void{
          for(var i:int=0; i<5;i++){
              class1=new MyClass()
              class1.counter=i
              class1.doThis()
          }
      }
         ]]>
      </mx:Script>
      </mx:Application>

       

      Here's the class: Myquestion is how can I set myArray[counter] (i.e. min the parent file) to some value I have stored in each instance of the class (e.g. counter).

       

      package {
          public class MyClass{   
          public var counter:int
          public function MyClass(){                                                           
              }
          public function doThis():void{                                                           
              //How can I set the value of myArray from here? For example:
              //myArray[counter]=counter
              }
          }
      }