I did some testing and debugging.
I even added a button in my main application. The clickevent just shows
the number of records of my datagrid.

click = "Alert.show(myCustComp.myDG.length");

And this gives me the exact number of records.
Even if I do following :

click = "Alert.show(myCustComp.myDG.source[0].fieldname");

it showed me the right record.
Finally I discovered that the fieldname I used to populate the datagrid
started with a capital letter while the fieldname itselves started with
a small letter.
It took me about 2 days to figure this out, but I'm quite sure I will
know faster next time.

Thanks for all your help.


--- In [email protected], "Tracy Spratt" <tspr...@...> wrote:
>
> In the line, dataProvider = "{_data}", how is _data in scope? If your
> handler sets the array collection in CustComp.as, .wait a minute, you
can't
> have an .as component and a .mxml component with the same name. I see
you
> wrote the same thing with Main. Maybe you are not saying these are
> different component/files?
>
>
>
> Have you debugged into the setter function to see if you have your
data
> there? If _data and myDG are in the same component, then what you
shave
> should work.
>
>
>
> Tracy Spratt,
>
> Lariat Services, development services available
>
> _____
>
> From: [email protected] [mailto:[email protected]]
On
> Behalf Of secrit.service
> Sent: Tuesday, March 31, 2009 5:49 AM
> To: [email protected]
> Subject: [flexcoders] Re: Custom Classes and Custom Events
>
>
>
> OK, I put the eventlistener on my instance of the RemoteObject custom
> component (in the main application) and guess what .... the
evenhandler is
> catched.
>
> BUT ... (there's always a but)
> I don't get my data in my datagrid custom component yet.
>
> Here's a short overview :
>
> Main.mxml
> <comp:CustComp id="myCustComp">
>
> Main.as
> private function databaseChange_EventHandler (evt:CustEvent):void {
> myCustComp.data = evt.data;
> }
>
> CustComp.as
> [Bindable]
> private var _data:ArrayCollection;
>
> public function set data (pData:ArrayCollection) : void {
> this._data = pData;
> }
>
> CustComp.mxml
> <mx:HBOX id = "myToolBar"/>
> <mx:DataGrid id = "myDG"
> dataProvider = "{_data}"/>
> <mx:HBOX id = "myStatusBar"/>
>
>
>
> In my main app I have the databaseChange_EventHandler. This
eventHandler
> gets the data as expected, meaning evt.data is an arrayCollection
containing
> all the records I needed. These records are mapped to an
arrayCollection of
> my instance of myCustComp which is made bindable and acts as the
> dataprovider of my datagrid in myCustComp.
>
> However my datagrid is not populated at all and to my opinion it
should.
> Any remarks?
>
> Thansk again!!
>
>
> --- In [email protected], "secrit.service" secrit-service@
> wrote:
> >
> >
> > Hi, thanks for your responses so far.
> > Based on what I read, I'm quite sure I'm on the right track. But
> > unfortunately it still doesn't work.
> >
> > I will explain my problem a bit more in detail, hoping to get a clue
of
> > what's wrong.
> >
> > When starting my application, I make a call to a mySQL database to
> > retrieve the available records and want to populate a datagrid with
> > these records.
> >
> > These are the steps I took :
> > -1- My main application is separated in a mxml- (main.mxml) and an
> > AS-file (main.as).
> > -2- To avoid lots of resulthandlers in my main application, I
created a
> > custom class extended from a RemoteObject (CustRO.as)
> > In this class I defined a public static const GET_ALL_DATA and
> > mapped it to "getAllData"
> > public const GET_ALL_DATA:String = "getAllData";
> > Also I defined a var _data of type ArrayCollection.
> > private var _data:ArrayCollection = new ArrayCollection();
> > In the constructor I added an eventListener :
> >
> > this.getOperation(GET_ALL_DATA).addEventListener("result",
> > getAllData_resultHandler);
> > -3- I also created a custom class extended from Event (CustEvent.as)
> > with following vars :
> > public static const CHANGE:String = "databaseChange";
> > private var _data:ArrayCollection;
> > -4- The main.mxml contains a custom component (myComp) with the
datagrid
> > in it (also included : toolbar and statusbar).
> > -5- In main.as I created an instance of CustRO.as (myRO).
> > -6- Using myRO.getOperation(myRO.GET_ALL_DATA).send() I make a call
to
> > the database
> > -7- In my resultHandler I wrote this._data = evt.result. While
debugging
> > my application I can see that this part works fine.
> > Also in the resultHandler I make a new instance of CustEvent and
> > called it myEventObj
> > var myEventObj:CustEvent = new
> > CustEvent(CustEvent.CHANGE);
> > myEventObj.data = this._data;
> > dispatchEvent(myEventObj);
> > -8- Event is dispatched. The only thing I need to do is to catch it.
> > Therefor I added a listener to my datagrid by adding following
> > line in the creationComplete of my custom component myComp
> > myDataGrid.addEventListener(CustEvent.CHANGE,
> > databaseChange_eventHandler);
> > -9- Finally in the databaseChange_eventHandler I map _data to
evt.result
> > and use _data as dataprovider of my datagrid.
> >
> > As I mentioned before, aa event with the correct data is dispatched,
but
> > in the listening-phase something is going wrong.
> > Does anyone have any idea where I missed?
> >
> > Thanks in advance.
> >
> > --- In [email protected], "secrit.service" secrit-service@
> > wrote:
> > >
> > >
> > > Hi all,
> > >
> > > The last couple of weeks I wrote my first application in Flex.
Today I
> > > want to refactor it, meaning : using custom classes and custom
events.
> > >
> > > I have following :
> > >
> > > I created an application with a couple of buttons and with a
custom
> > > component (myCustomComp) in it. This custom component is based on
a
> > > Vbox an contains :
> > > - an HBox (mySearchbar) with a textfield and button
> > > - a datagrid which contains data from a database
> > > - an HBox (myToolbar) with a button and a label
> > >
> > > The buttons are used for adding, modifying and deleteing records
of
> > the
> > > database. SO I was thinking of creating a custom event
> > (myCustomEvent).
> > >
> > > The code I have so far is following :
> > >
> > > package events {
> > >
> > > import flash.events.Event;
> > >
> > > public class myCustomEvent extends Event {
> > >
> > > public function SpellEvent(type:String) {
> > > super(type);
> > > }
> > >
> > > override public function clone():Event{
> > > var evt:myCustomEvent = new myCustomEvent(type);
> > > return evt;
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > I was thinking of adding event listners to my buttons. For example
my
> > > button to add a new record will have a addRecordEventListener. In
this
> > > listener I create a new instance of myCustEvent and pass my new
record
> > > as a parameter.
> > > The same I will do with my button to delete a record.
> > >
> > > My question is where and how I should make the difference between
the
> > 2
> > > operations.
> > > I suppose I have to create a new instance of my event and besides
my
> > new
> > > record I also need to pass the type of operation : something like
new
> > > myCustomEvent(newRecord, "addRecord") or new
myCustomEvent(newRecord,
> > > "deleteRecord"). But in this case, how do I process the different
> > > operations?
> > >
> > > I'm lost and hoping for a clear answer.
> > >
> > > Thanks
> > >
> >
>


Reply via email to