3 Replies Latest reply on Jul 17, 2009 11:11 AM by vpxav

    [noob] Passing data to child module

    vpxav

      Hello everyone,

      I'am a beginner with Flex 3 and have a question regarding modules.

      I have a component in my module and I want to change its text property when the module is ready.

      My problem is that the text property is never changed.

      Here's my code:

       

           the Application:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
               <![CDATA[
                   import mx.controls.Label;
                   private var montitre:Label;                 
                  private function initM1():void{
                      montitre=(m1.child as myModule).label1;
                      montitre.text="data sent!";
                  }
               ]]>
          </mx:Script>
          <mx:Panel width="100%">
              <mx:ModuleLoader id="m1" url="myModule.swf" ready="initM1()"/>
          </mx:Panel>
      </mx:Application>

           the module myModule.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
          <mx:Label text="hello" id="label1" width="100%" height="100%"/>
      </mx:Module>

      Thanks for your help

        • 1. Re: [noob] Passing data to child module
          cemef

          Did you try creating a variable of the myModule type in the main MXML file? (var myVar:myModule = new myModule()). Once you do that, you should be able to change it's properties from the first file using myVar.label1.text = "new text".

           

          You should also read a little about Object Oriented Programming, at least about variables specifiers like public / private, static, etc.

          1 person found this helpful
          • 2. Re: [noob] Passing data to child module
            vpxav Level 1

            Hello thanks for your help.

            I (tried) to follow your instructions, you're right, I've still things to learn...

             

            But... this is what I did but it doesn't change my text either:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:Script>
                     <![CDATA[
                         import mx.controls.Label;        
                        private function initM1():void{
                            var myVar:myModule = new myModule();
                            myVar.label1.text="data sent!";
                        }
                     ]]>
                </mx:Script>
                <mx:Panel width="100%">
                    <mx:ModuleLoader id="m1" url="myModule.swf" ready="initM1()"/>
                </mx:Panel>
            </mx:Application>

            Could you send me the correct code? I'm sure this is very easy but I can't find a clear enough (at least for me) documentation about this...

             

            Thank you so much for your time.

            • 3. Re: [noob] Passing data to child module
              vpxav Level 1

              Ok, I found the solution (while there's is still another problem with the ready event not being sent, it works when the button is clicked):

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                  <mx:Script>
                       <![CDATA[
                           import mx.controls.Label;
                           private var myVar:myModule;    
                          private function initM1():void{
                              myVar = m1.child as myModule;
                              myVar.label1.text="data sent!";
                          }
                       ]]>
                  </mx:Script>
                  <mx:Panel width="100%">
                      <mx:ModuleLoader id="m1" url="myModule.swf" ready="initM1()"/>
                      <mx:Button click="initM1();"/>
                  </mx:Panel>
              </mx:Application>