function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Steve BairSteve Bair 

Flex: Using apex.query in a component

I am trying to move the data reading portion of my actionscript to a class residing in a spearate .as file.  I extracted the code that I needed from the main file and put it into the new file.  Here is the structure...
 
package com.mydomain.components
{
     import all the same stuff as the main file
 
     public class Office
     {
          public class getData():ArrayCollection
          {
               apex.query(.......);
          }
     }
}
 
When the new file is saved, the error is 1120: Access of undefined property apex.
 
Does anyone know what I need to do so that flex can resolve the apex reference in the component?
 
Thanks.
 
 
Ron HessRon Hess
your class office, can expose/provide a constructor that accepts apex as a parameter, then store it in a class global.

now your class can access and use the apex as a variable shown in your code.

when you create the class office you pass in the apex connection created in you main file.
Steve BairSteve Bair
Thank you for the reply.  That looks reasonable.
 
My code now looks like this...
 
package com.mydomain.components
{
     import all the same stuff as the main file
     private var apx:Object = new Object;
 
     public class Office
     {
          public function Office(a:Object)
          {
               super();
               apx = a;
          }
 
          public function getData():ArrayCollection
          {
               apx.query(.......);
          }
     }
}
 
 
In the caller, I'm using this code...
 
import com.mydomain.Office;
.....
.....
public var CallForData:Office = new Office(apex);
public var ar:ArrayCollection = new ArrayCollection;
.....
.....
ar = CallForData.getData();
 
 
This results in an error saying that the variable apx in the class is null.  I'm sure that I'm doing something wrong in the declarations or calling somewhere, but I haven't been able to find it.
 
What am I doing wrong?
 
 
 
Steve BairSteve Bair

OK. I figured it out and took a slightly different approach.

I added a property to the class called "apx" declared as type Connection.  From the caller, I just do obj.apx = apex;.  This calls the set apx method in the class.

Bingo, there is apex -- all ready to use.

 

Thanks for your help.