Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

trouble with flex & mysql

Avatar

Level 1
Hi all,

I'm new to using FLEX and ActionScript (but I have a lot of
experience using PHP, MySQL, JavaScript AJAX, etc)

Anyhow, I'm trying to put a new FLEX frontend on an existing
project that currently has an HTML/CSS/JavaScript frontend. I know
all of the php functions work in and of themselves, but I'm trying
to request data from MySQL via PHP from this new FLEX frontend I've
built out, and I'm encountering errors. Specifically, here is the
error message that I get when the user clicks the button that
should be gathering the data from the database and populating a
DataGrid control:



Error: Unexpected < encountered

at
com.adobe.serialization.json::JSONTokenizer/parseError()[C:\Development\ContractProjects\Adobe\as3corelib\src\com\adobe\serialization\json\JSONTokenizer.as:546]

at
com.adobe.serialization.json::JSONTokenizer/getNextToken()[C:\Development\ContractProjects\Adobe\as3corelib\src\com\adobe\serialization\json\JSONTokenizer.as:171]

at
com.adobe.serialization.json::JSONDecoder/nextToken()[C:\Development\ContractProjects\Adobe\as3corelib\src\com\adobe\serialization\json\JSONDecoder.as:86]

at
com.adobe.serialization.json::JSONDecoder()[C:\Development\ContractProjects\Adobe\as3corelib\src\com\adobe\serialization\json\JSONDecoder.as:63]

at
com.adobe.serialization.json::JSON$/decode()[C:\Development\ContractProjects\Adobe\as3corelib\src\com\adobe\serialization\json\JSON.as:81]

at ClientManager/handleFooRes()[C:\Documents and Settings\My
Documents\Flex Builder 3\ClientManager\src\ClientManager.mxml:224]

at ClientManager/__search_all_foo_serv_result()[C:\Documents
and Settings\My Documents\Flex Builder
3\ClientManager\src\ClientManager.mxml:265]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at mx.rpc.http.mxml::HTTPService/
http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.1.0\frameworks\projects\rpc\...

at mx.rpc::AbstractInvoker/
http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.1.0\frameworks\projects\rpc\src...

at
mx.rpc::Responder/result()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]

at
mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]

at
DirectHTTPMessageResponder/completeHandler()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:381]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()



I'll post some of the pertinent code below:

Here are my imports:

import flash.net.sendToURL;

import mx.automation.codec.AssetPropertyCodec;

import mx.rpc.events.ResultEvent;

import mx.controls.TextInput;

import mx.events.DataGridEvent;

import mx.collections.ArrayCollection;

import com.adobe.serialization.json.JSON;



This is the array collection that will serve as the
DataProvider for the DataGrid:

[Bindable]

private var searchDataArray:ArrayCollection;



This is the control that the user uses to submit the request
for data from the DB:

<mx:VBox label="Search Records">

<mx:TabNavigator id="searchwin" width="100%"
height="100%">

<mx:VBox label="foo">

<mx:HBox label="foo" id="searchfoo">

<mx:Label text="Find: "/>

<mx:TextInput id="foo_search_param"/>

<mx:Label text="In"/>

<mx:ComboBox dataProvider="{fooarray}"
id="foo_search_filter"></mx:ComboBox>

<mx:Button id="foo_search_submit" label="Search Records"
click="showSearchFooGrid()"></mx:Button>

<mx:Button id="foo_search_all" label="Get All Records"
click="showAllFooGrid()"></mx:Button>

</mx:HBox>

<mx:DataGrid id="searchFooGrid" visible="false"
width="100%" height="50%" dataProvider="{searchDataArray}">

<mx:columns>

<mx:DataGridColumn headerText="ID" dataField="cb_id"/>

<mx:DataGridColumn headerText="Status"
dataField="status"/>

<mx:DataGridColumn headerText="Service Date"
dataField="service_date"/>

<mx:DataGridColumn headerText="First Name"
dataField="customer_first_name"/>

<mx:DataGridColumn headerText="Last Name"
dataField="customer_last_name"/>

<mx:DataGridColumn headerText="Start"
dataField="start"/>

<mx:DataGridColumn headerText="City"
dataField="city"/>

<mx:DataGridColumn headerText="State"
dataField="state"/>

<mx:DataGridColumn headerText="Store Number"
dataField="store_num"/>

<mx:DataGridColumn headerText="Order Number"
dataField="order_num"/>

</mx:columns>

</mx:DataGrid>

<mx:TextArea id="searchFooNotes" wordWrap="true"
width="100%" height="40%" visible="false"/>

<mx:Label id="searchFooLabel"></mx:Label>

</mx:VBox>



The grid will not be visible to the user until the button is
clicked. This is the function that makes the grid visible, and
triggers the HTTPService object to send the request to PHP:

private function showAllFooGrid():void

{

searchFooGrid.visible = true;

searchFooNotes.visible = true;

search_all_foo_serv.send();

}



Here is the HTTPService object it calls:

<mx:HTTPService id="search_all_foo_serv"
url="./php/phpfile.php" useProxy="false" method="GET"
resultFormat="text" result="handleFooRes(event)">

<mx:request xmlns="">

<rec_action>"show_all"</rec_action>

<search_type>"foo"</search_type>

</mx:request>

</mx:HTTPService>



Here is the result handler:

private function handleFooRes(event:ResultEvent):void

{

var rawArray:Array;

var rawData:String = String(event.result);

rawArray = JSON.decode(rawData) as Array;

searchDataArray = new ArrayCollection(rawArray);

searchFooNotes.text = rawArray.text;

}



FWIW, here's the related portion of the php backend:

the foo class that gets instantiated in $cdata contains no
methods, and only empty properties to be filled by the queried DB
data.

public function getAllFromFoo()

{

$query = sprintf("SELECT * FROM foo");



$res = @mysql_query($query, $this->sql);

if (!$res) { return false; }

$fooarray = array();

while ($data = @mysql_fetch_assoc($res))

{

$cdata = new foo();

$cdata->status = $data['status'];

$cdata->customer_first_name =
$data['customer_first_name'];

$cdata->customer_last_name = $data['customer_last_name'];

$cdata->start = $data['start'];

$cdata->city = $data['city'];

$cdata->state = $data['state'];

$cdata->service_date = $data['service_date'];

$cdata->store_num = $data['store_num'];

$cdata->order_num = $data['order_num'];

$cdata->notes = $data['notes'];

array_push($fooarray, $cdata);

}

@mysql_free_result($res);

echo json_encode($fooarray);

}



if anyone could help me figure out why I'm receiving these
errors, I would greatly appreciate it.

Feel free to post any answers here, or to my email at the
following account:

jsteele1_at_mail.com (replace the '_at_' with '@'
[obviously])

Thanks in advance,

Jason.
0 Replies