Posts Tagged ‘flex’
27
May

A simple thing that I learnt today in Flex (I am very much a beginner as you can see) – adding a gradient to the flex background.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundGradientColors="[0xAAAAAA,0x000000]" horizontalAlign="left" verticalGap="15" horizontalGap="15">

This will add a horizontal gradient starting from light gray and ending in black – looks real nice.

Remember to prefix your color codes with 0x (zero and alphabet x) – and not #

, ,

04
May

Here you are going to connect a Flex application with PHP.
The values are saved as an XML format in that PHP file.

You can create a new Flex Project and paste the following code in the mxml file:

<?xml version="1.0" encoding="utf-8"?> <!--mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="productsRequest.send()" --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:XML id="productsRequest" source="http://localhost/flex/products.php"></mx:XML> <mx:DataGrid x="20" y="80" id="productGrid" width="400"  dataProvider="{productsRequest..product}" > <mx:columns> <mx:DataGridColumn headerText="Name" dataField="name" /> <mx:DataGridColumn headerText="Price" dataField="price" /> </mx:columns> </mx:DataGrid> </mx:Application>

Here you are going to use <mx:XML> which connects the mxml application with a php file.
Then an <mx:DataGrid> is used which shows a datagrid with specified columns.

Then create a folder inside /xamp/htdocs/
Here I have created a folder named flex and inside that folder create a new php file which I named as products.php
Copy the code below into products.php

<?php $a = '<?xml version="1.0" encoding="utf-8" ?><products> <product><name>Mobile Phone</name><price>$199</price></product> <product><name>Car Charger</name><price>$34</price></product> <product><name>iPhone</name><price>$149</price></product> <product><name>10 TB HDD</name><price>$150</price></product> <product><name>Acer Laptop</name><price>$600</price></product> <product><name>HP Laptop</name><price>$640</price></product> <product><name>iPod</name><price>$140</price></product> </products>'; header("Content-Type: text/xml"); print $a; ?>

Here in the  php file, data is saved in XML format and it is printed inside the datagrid defined in the mxml file.

Start Xamp and run the mxml file in Adobe Flex.
You can see a data grid with populated values.

, ,

20
Apr
1. Go to File > New > Flex Project.
2. In the dialog box, type helloWorld as the project name, and specify a project directory called helloWorld under the web root. Select Web application option as the application type, and then select an application server type of PHP.
3. Also give main source folder name
4. In the design view change value for layout as ‘vertical’.
5. Write following code in helloworld.mxml of code view.
<mx:HTTPService id="phpService"
url="http://localhost/helloWorld/helloWorld.php"
resultFormat="object" result="showResult()"/>
We can use an HTTPService component with any kind of server-side technology, including PHP pages.Here ,the service has an ID of phpService and a URL pointed to the helloWorld.php file, and the result format is generic object. The service is also set to call the showResult() function when it gets a result.
To actually use the service, its send method needs to be called.
For that we use <mx:Button> control .
<mx:Button label=”Call PHP” click=”phpService.send()”/>
Now, we need to create the showResult() function in an <mx:Script> block, below the <mx:HTTPService> tag.
<mx:Script>
<![CDATA[
import mx.controls.Alert;
privatefunction showResult():void {
Alert.show(phpService.lastResult as String,'Message from PHP');
}
]]>
</mx:Script>
The ActionScript code first declares an Import statement,which allows the application to use the Alert class from the mx.controls package. Secondly, it creates the showResult() function. This function displays an alert pop-up with the title "Message from PHP." The text within the alert box is the result from the HTTPService call to the helloWorld.php file.
6. Create a directory inside xampp/htdocs/ as helloWorld and a file helloworld.php inside that directory. The code is given below:
<?php
print "Hello world";
?>
7. Run the application to get the result as shown below.

,