views:

580

answers:

2

I Have a unique id generated for each record that i store into the database i want to pass that id to php and run a select statement against that and get a value back from the database and pass it back to flash, what is the best possible way to do it?

ps am using AS3

+1  A: 

I don't really see your problem. What makes this really different from a client-side javascript invoking a server-side PHP? I mean, simply create a URLLoader with the appropriate URLRequest object (can also be a POST request), add an event handler for the COMPLETE event, and parse the returned document. I recommend XML, because that is easy to parse from AS3, but JSON and plain text should work as well.

David Hanak
+2  A: 

You have to call the php script which makes the sql connection and gets the value.

Here: http://livedocs.adobe.com/flex/2/langref/flash/net/URLLoader.html#includeExamplesSummary

The important part is here:

public function URLLoaderExample() {
        var loader:URLLoader = new URLLoader();
        configureListeners(loader);

        var request:URLRequest = new URLRequest("urlLoaderExample.txt");
        try {
            loader.load(request);
        } catch (error:Error) {
            trace("Unable to load requested document.");
        }
    }

And here:

private function completeHandler(event:Event):void {
        var loader:URLLoader = URLLoader(event.target);
        trace("completeHandler: " + loader.data);

        var vars:URLVariables = new URLVariables(loader.data);
        trace("The answer is " + vars.answer);
    }

In your php script you just have a print at the end:

<?php
   $value = Select Statement to get that damn value out of the damn database
   print $value;
?>

You will be able to read $value out of loader.data.

monkee