1 Reply Latest reply on Jun 14, 2009 9:18 PM by Flex harUI

    How to broadcast to multiple instances

    SiHoop Level 1

      The following includes 3 files: A main Flex file and two classes. Only last instance created in the loop receives the myClass.doThis() method-- it only fires once. What I want to do is to broadcast to all of the instances. What change do I need to make to the myMethod function in Class1.as to make this work.

      Thank you!

       

      <?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 myClass: Class1
      private function init():void{
           myClass=new Class1()
           myClass.myMethod()
      }
          ]]>
        </mx:Script>
      </mx:Application>

       

      Class1.as

      package {
           public class Class1{   
           public var counter:int
           private var myClass:Class2
           public function Class1(){   
               for(var i:int=0; i<5;i++){
                   myClass=new Class2()
                   myClass.counter=i
               }                                                       
           }
               public function myMethod():void{                                                           
                   myClass.doThis()
               }   
           }
      }

       

      Class2.as

      package {
           public class Class2{   
           public var counter:int
           public function Class2(){                                                           
               }
           public function doThis():void{                                                           
               trace("counter="+counter)
               }
           }
      }

       

       

      Message was edited by: SiHoop. I changed the posting to make it simpler.