8 Replies Latest reply on Jul 23, 2009 11:02 PM by TCL9

    1120: Access of undefined property.

    TCL9

      Hi, am not able to access arr1 arraycollection even though it was declared as a public class variable within the generateCollection function.

       

      The codes are below, appreciate any help?

       

      package Components.UnitSelector{
          import mx.collections.ArrayCollection;
          import mx.rpc.events.ResultEvent;
          import mx.rpc.http.HTTPService;
         
          public class DataUtil
          {
              [Bindable]
              public var arr1:ArrayCollection     = new ArrayCollection();
             
              public  function callPHP():void
                  {
                     
                  var hs:HTTPService = new HTTPService();
                 
                  hs.url = 'Picture.php';
                 
                  hs.addEventListener( ResultEvent.RESULT, resultHandler );
                 
                  hs.send();
                 
                  }
                 
                  public function resultHandler(event:ResultEvent):void
                  {
                      arr1 = event.result.root.images.image as ArrayCollection;           
                  }
                     
              public static function generateCollection() : UnitsDataCollection
              {
                  var result : UnitsDataCollection = new UnitsDataCollection();
                 
                  var icons : ArrayCollection = new ArrayCollection();
                 
                  var i : int;
                 
                  for(i=0; i<arr1.length; i++)
                  {
                      icons.addItem( new Icons( i, "Air", arr1[i]));
                  }

       

                  result.icons = icons;
                 
                  return result;
              }

       

          }
      }

        • 1. Re: 1120: Access of undefined property.
          _Natasha_ Level 4

          Hi,

          variable should be also static to access it from this function.

          • 2. Re: 1120: Access of undefined property.
            TCL9 Level 1

            Wow it works! Thanks alot!

             

            Anyway i got another qn

             

            arr = event.result.root.images.image as ArrayCollection;

             

            the root.images.image is the data recieved from a PHP file and it is binded to the array arr using event result. Is there any ways to bind data from PHP to the array arr without using event result?

            • 3. Re: 1120: Access of undefined property.
              _Natasha_ Level 4

              It's impossible to get ArrayCollection directly. You can create ArrayCollection on Array result.

              Somethings like this:

              arr = new ArrayCollection(event.result.root.images.image as Array);

               

              Check the type for event.result.root.images.image in debugger.

              • 4. Re: 1120: Access of undefined property.
                TCL9 Level 1

                oh okay! Now i got a problem, my array arr is null. This means that my the data from my PHP file is not binded to array arr.

                 

                 

                This is my code:

                 

                package Components.UnitSelector{
                    import mx.collections.ArrayCollection;
                    import mx.rpc.events.ResultEvent;
                    import mx.rpc.events.FaultEvent;
                    import mx.controls.Alert;
                    import mx.events.FlexEvent;
                    import mx.rpc.http.HTTPService;
                   
                    public class DataUtil
                    {
                        [Bindable]
                        public static var arr:ArrayCollection = new ArrayCollection();
                       
                        public static function callPHP():void
                            {
                               
                            var hs:HTTPService = new HTTPService();
                           
                            hs.url = 'Picture.php';
                           
                            hs.addEventListener( ResultEvent.RESULT, resultHandler );
                           
                            hs.addEventListener( FaultEvent.FAULT, faultHandler );
                           
                            hs.send();
                           
                            }
                           
                            public static function resultHandler(event:ResultEvent):void
                            {
                                arr = event.result.root.images.image as ArrayCollection;           
                            }
                           
                            public static function faultHandler(event:FaultEvent):void
                            {
                           
                                Alert.show( "Fault Response from HTTPService call:\n " );
                            }
                               
                        public static function generateCollection() : UnitsDataCollection
                        {           
                           
                           
                            var result : UnitsDataCollection = new UnitsDataCollection();
                           
                            var icons : ArrayCollection = new ArrayCollection();
                           
                            var i : int;
                           
                            callPHP();
                           
                            for(i=0; i<(arr.length); i++)
                            {   
                                icons.addItem( new Icons( i, "Air", "Air Quality/" + arr[i]));
                                trace(arr[i]);
                            }

                 

                             result.icons = icons;
                           
                            return result;
                        }

                 

                    }
                }

                • 5. Re: 1120: Access of undefined property.
                  _Natasha_ Level 4

                  It's wrong:

                            public static function resultHandler(event:ResultEvent):void

                              {
                                  arr = event.result.root.images.image as ArrayCollection;           
                              }    

                   

                  Correct:

                  arr = new ArrayCollection(event.result.root.images.image as Array); 

                   

                  And it's correct only if event.result.root.images.image is an Array.

                   

                  Is your data is XML or not?

                  • 6. Re: 1120: Access of undefined property.
                    TCL9 Level 1

                    event.result.root.images.image is not an Array, it is in XML form. The data is passed from PHP to FLEX then insert into the array arr in FLEX, it is not an array in PHP.

                    • 7. Re: 1120: Access of undefined property.
                      _Natasha_ Level 4

                      If it's XML, arr will have XMLList type and it's not an Array.

                       

                      So if you want to get advanteges like ArrayCollection you need to use XMLListCollection type for arr.

                      • 8. Re: 1120: Access of undefined property.
                        TCL9 Level 1

                        hmm can you take a look at this both files. This 2 files can work even though i did not use the XMLList type.

                         

                        FLEX :

                         

                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="callPHP();">

                         

                             <mx:Script>
                                <![CDATA[
                               
                                import mx.rpc.http.HTTPService;
                                import mx.controls.Alert;
                                import mx.events.FlexEvent;
                                import mx.rpc.events.FaultEvent;
                                import mx.rpc.events.ResultEvent;
                                import mx.collections.ArrayCollection;
                               
                                [Bindable]
                                private var arr:ArrayCollection = new ArrayCollection();
                               
                                private function callPHP():void

                         

                                {
                               
                                var hs:HTTPService = new HTTPService();
                               
                                hs.url = 'Picture.php';
                               
                                hs.addEventListener( ResultEvent.RESULT, resultHandler );
                               
                                hs.addEventListener( FaultEvent.FAULT, faultHandler );
                               
                               
                                hs.send();
                               
                                }
                           
                               
                                private function resultHandler(event:ResultEvent):void
                                {

                                    arr = event.result.root.images.image as ArrayCollection;

                                            
                                }
                               
                                private function faultHandler(event:FaultEvent):void
                                {
                                   
                                    Alert.show( "Fault Response from HTTPService call:\n " );
                                } 
                               
                                ]]>
                            </mx:Script>
                           
                           
                            
                            <mx:TileList id="tilelist"
                                    dataProvider="{arr}"
                                    width="781" x="28" y="140"
                                    dragEnabled="true"
                                    dropEnabled="true"
                                    dragMoveEnabled="true">
                           
                                 <mx:itemRenderer>
                           
                                      <mx:Component>
                           
                                           <mx:Image source="Pic/images/{data}" width="80" height="55"/>
                           
                                     </mx:Component>
                           
                                 </mx:itemRenderer>
                           
                            </mx:TileList>

                         

                           
                        </mx:Application>

                         

                        PHP :

                         

                        <?php

                         

                        echo '<?xml version="1.0" encoding="utf-8"?>';

                         

                        ?>

                         

                        <root>

                         

                        <images>

                         

                        <?php

                         


                            //Open images directory

                         


                            $dir = dir("images");

                         

                            //List files in images directory
                           
                                while (($file = $dir->read()) !== false)
                               
                                {
                               
                                    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
                                   
                                    echo "<image>" . $file . "</image>";
                               
                                }
                           
                        ?>

                         

                        </images>

                         

                        </root>