I'm not sure having a visual component doing database calls is a good 
architecture, though I haven't really gone through your code.

In an MVC architecture the UI should raise an event. The model should 
recognise the event, initiate the DB transfer, on transfer complete you can 
raise another event to alert the GUI to update itself or just bind to the 
model.

I suspect that in your case, the canvas should not be responding to creation 
complete by trying to initiate the creation of the person for display. On 
creation complete, you should ask the model to fetch a person. The model 
should then initiate the DB transfer and handle the asynchronous completion 
event. On completion, it can either update part of the model with the person 
data (and use binding from the GUI to update the display), or raise an event 
to alert the GUI to update itself and create the visual for the person.

Paul

----- Original Message ----- 
From: "johantrax" <[EMAIL PROTECTED]>
To: <flexcoders@yahoogroups.com>
Sent: Wednesday, October 31, 2007 4:25 PM
Subject: [flexcoders] Hold execution untill result from database


> Hi all (again... I'm having a productive day ;) )
>
> I'm trying to lift the creation of components to a new level (at
> least, for me)
> What I have: (if it is possible...)
> 1.
> I have an .AS-class which describes a person. To keep it simple, the
> person only has a name(String) and a photo(String - the URI).
> 2.
> A/ I have a databasetable with the following structure
>        ObjectClass | propertyName | renderType
> B/ Another database table as follows
>        renderType | bindPropertyName
> 3.
> I have an AS-class(UICF) in my own lib, having following method
>        public static getUIComponent(object:Object, objectClass:Class,
> propertyName:String, propertyType:Class):UIComponent
> 4.
> I have a canvas
>
> What should happen:
> In the creationComplete of the canvas(4) a new Person is created:
>        var p:Person = new Person("Foo", "images/bar.jpg");
> Now the canvas(4) calls the getUIComponent(3) for rendering the image:
>        var c:UIComponent = UICF.getUIComponent(p, Person, "photo",
> String);
> The method(3) returns the correct component, being an imagecomponent
> and the canvas(4) just adds it to it's children:
>        this.addChild(c);
>
> The problem is inside getUIComponent(3). This method should do a call
> to my database to find out which type of component it should create
> and which property to set. For this example, the db would look like this:
>    First Table
>        ObjectClass | propertyName | renderType
>           Person        photo         Image
>    Second Table
>        renderType | bindPropertyName
>          Image          source
>
> However, if I recall correctly, all database requests made by Flex are
> Asynchronous. One option I see, is to have a boolean which gets sets
> by a resulthandler, and create a lock-up-loop in getUIComponent.
> However there might just be another (better?) way, to wait for my
> response and then create and return the correct component.
>
> Thanks in advance,
> --Johan
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
> 

Reply via email to