0

The more I read the more it confuses me...

So inside action script I write down the functions of the flex mobile project, and inside the php files I write down the functions that I use to contact the database with?

Are there any sample applications that uses both actionscript and PHP . Now I am also getting confused about amfphp. Any help would be great

1 Answers1

0

You don't need any amfphp yet, it is for some advanced cases.

To save smth to database you already have a correct picture: your database commands (SQL commands using PDO) should be in the .php files.

And from your mobile flex app you call those .php files using either URLLoader, URLStream (slightly more advanced) or HTTPService.

Here a View from my app, it loads a weekly top of players from PostgreSQL in JSON format:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark"
        viewActivate="startLoading(event)"
        viewDeactivate="cancelLoading(event)"
        title="Weekly top">

    <fx:Declarations>
        <s:MultiDPIBitmapSource id="BACK"
            source160dpi="@Embed('assets/icons/low-res/back.png')"
            source240dpi="@Embed('assets/icons/mid-res/back.png')"
            source320dpi="@Embed('assets/icons/high-res/back.png')"/>
        <s:MultiDPIBitmapSource id="LOAD"
            source160dpi="@Embed('assets/icons/low-res/load-top.png')"
            source240dpi="@Embed('assets/icons/mid-res/load-top.png')"
            source320dpi="@Embed('assets/icons/high-res/load-top.png')"/>
    </fx:Declarations>

    <s:states>
        <s:State name="portrait"/>
        <s:State name="landscape"/>
    </s:states> 

    <s:navigationContent>
        <s:Button icon="{BACK}" label.landscape="Back" click="navigator.popView()"/>
    </s:navigationContent>

    <s:actionContent>
        <s:BusyIndicator symbolColor="0xFFFFFF" />
    </s:actionContent>

    <fx:Script>
        <![CDATA[
            import com.brokenfunction.json.decodeJson;
            import spark.events.ViewNavigatorEvent;

            private const TOP:String = 'http://XXXX.com/top-json.php';

            private var _urlLoader:URLLoader = new URLLoader();

            private function startLoading(event:ViewNavigatorEvent):void {
                _urlLoader.addEventListener(Event.COMPLETE, handleComplete);
                _urlLoader.load(new URLRequest(TOP));
            }

            private function cancelLoading(event:ViewNavigatorEvent):void {
                _urlLoader.close();
            }

            private function handleComplete(event:Event):void {
                var loader:URLLoader = URLLoader(event.target);
                try {
                    var obj:Object = decodeJson(loader.data, true);
                    navigator.pushView(Top, obj.aaData);
                } catch (e:Error) {
                    trace('Invalid JSON: ' + loader.data);
                    navigator.popView();
                }
            }
        ]]>
    </fx:Script>    

    <s:BitmapImage source="{LOAD}" horizontalCenter="0" verticalCenter="0" scaleMode="letterbox" />
</s:View>
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416