Hello to all.
I'm trying to create a flex web application connected to a database with php.
-Main Application-
ActionScript Code:
<fx:Declarations>
<components:Com_Db_Users id="com_db_users"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
protected function start():void
{
txtarea_debug.text = com_db_users.getId();
}
]]>
</fx:Script>
<s:states>
<s:State name="test"/>
</s:states>
<s:TextArea id="txtarea_debug" x="10" y="10" width="365" height="600"/>
<s:Button id="btn_start" x="419" y="513" label="Load" click="start()"/>
-Component-
ActionScript Code:
<fx:Declarations>
<s:HTTPService id="userRequest" url="database/test.php" useProxy="false" method="POST"
result="resultHandler(event)" fault="faultHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
// component core
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
// db
[Bindable] protected var id:int = 0;
[Bindable] protected var get_id:Boolean = false;
private function faultHandler(fe:FaultEvent):void
{
Alert.show(fe.fault.message);
}
private function resultHandler(re:ResultEvent):void
{
//Alert.show(String(re.result.query));
if (get_id)
{
get_id = false;
if (re.result.query == "loaded")
{
id = re.result.id;
}
else if (re.result.query == "empty")
{
id = 0;
}
}
}
public function getId():Boolean
{
var tmp_nick:String = val;
get_id = true;
var params:Object = {};
params.get_id = get_id;
userRequest.send(params);
if (id > 0)
return true;
else
return false;
}
]]>
</fx:Script>
The problem is that i want that the function getId(), in the component, will return a value processed after the php file is readed, so i can pass it to the module/component/application that used it. But this will never happen because this part
codice:
ActionScript Code:
if (id > 0)
return true;
else
return false;
will always be read before that the php file will be readed. How can i do?is there a way to tell him to wait till the file is read and then continue?
Thanks in advice and sorry for my bad english.