Problem with setting the xml dataprovider for combo box - apache-flex

I am trying to get the drop down list of combobox by using a php file. That php file returns an xml string which has been used as data provider for combobox.
I followed this thread too but in vain.
Details
I have set the creationComplete attribute of mx:Application to init(). In the init() function i have sent the following HTTPService
<mx:HTTPService id="interfaces" url="interfaces.php" resultFormat="e4x" method="POST">
</mx:HTTPService>
Combo Box:
Update:
The xml should look like
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<ifaces>
<iface>
<option>eth0</option>
</iface>
<iface>
<option>eth1</option>
</iface>
</ifaces>
but if i execute interfaces.php in browser the only things that gets display is
eth0eth1
whereas i am echoing the string that contains whole xml data. Shouldn't whole xml type of string display? :(

The problem is that ifaces is the root element of your XML, so interfaces.lastResult == ifaces. So the XMLList you want is interfaces.lastResult.iface.
This is a whole main class that works for me:
`<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
initialize="{interfaces.send();}">
<mx:HTTPService id="interfaces" url="interfaces.xml" resultFormat="e4x" method="POST">
</mx:HTTPService>
<mx:ComboBox dataProvider="{interfaces.lastResult.iface}" labelField="option"/>
</mx:Application>`

Related

Flex 4 XML Attribute Binding Not Working?

For some reason this seems to no longer work in flex 4, it used to work in flex 3...
[Bindable]
public var xmlTitle:String = "TEST";
[Bindable]
public var xmlData:XML = <Data title={xmlTitle}> ... </Data>;
I am setting the xmlTitle variable outside of the component:
<local:Comp xmlTitle="Some Title" />
I have tried with getter / setters...etc. It just does NOT update when changing, it shows the default value and never changes. Is this a known new bug in flex 4?
I can't say I've ever done that before, mostly because it's extremely bad form. If you want to create an xml, using the XML object in mxml to create it in the declarations:
<fx:Declarations>
<fx:XML id="xmlData" xmlns="">
<Data title="{xmlTitle}">
</Data>
</fx:XML>
</fx:Declarations>
Should work just fine.
Using {} with XML in ActionScript is not data binding. It takes current variable's value in the moment of forming XML. And doesn't change it later. So this behavior is absolutely expectable.

popup editor for datagrid items - hangs the browser

i've got a pretty straightforward thing: a datagrid which renders some items. clicking on an item would bring up a popup editor (as the item has lots of properties and may not be edited right in the datagrid).
the popup contains just a form and a [Bindable] reference to the item it edits (which is passed from itemClick handler of the datagrid). form's default values are taken by binding to corresponding item properties with {} notion, while form values are bound back to the item using mx:Binding tags.
and now the problem. when the popup is brought up for the first time, everything is fine. however, when after being closed the popup is brought up again by clicking on the same item, the browser hangs (afaik because of change watchers being endlessly fired resulting in stackoverflow or something similar).
we have same behaviour in Safari, IE and Chrome, so i guess it's not to do with something browser-related. removing either [Bindable] from the item reference in the popup or mx:Binding tags from editors suppresses the problem, but of course the editing no longer works.
i'm banging my head against the wall for several days already, but still can't make it work. does it ring a bell to someone, what can be wrong in here (what can be damn easier that this)?
here's the code of the popup:
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" title="Details"
showCloseButton="true" close="PopUpManager.removePopUp(this);" creationComplete="PopUpManager.centerPopUp(this)">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import my.Detail;
[Bindable] private var _documentDetail:Detail;
public function set documentDetail(value:Detail):void {
this._documentDetail = value;
}
public function set readOnly(value:Boolean):void {
if (value) {
this.currentState = "read-only";
}
}
]]>
</mx:Script>
<mx:states>
<mx:State name="read-only">
<mx:SetProperty target="{startDate}" name="enabled" value="false"/>
<mx:SetProperty target="{comments}" name="enabled" value="false"/>
</mx:State>
</mx:states>
<!--
<mx:Binding source="this.startDate.selectedDate" destination="_documentDetail.startDate"/>
<mx:Binding source="this.comments.text" destination="_documentDetail.comment"/>
-->
<mx:VBox width="100%" height="100%">
<mx:FormItem label="{resourceManager.getString('eRequestAppli','startdate')}:" labelWidth="160" width="100%">
<mx:DateField id="startDate" width="100%" selectedDate="{_documentDetail.startDate}" formatString="{resourceManager.getString('eRequestAppli', 'dateformat')}" editable="false"/>
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('eRequestAppli','comments')}:" labelWidth="160" width="100%" height="79">
<mx:TextArea id="comments" width="100%" height="100%" text="{_documentDetail.comment}" editable="false"/>
</mx:FormItem>
</mx:VBox>
</mx:TitleWindow>
here's how i call it:
private function show(detail:Detail, readOnly:Boolean=false):void {
var popup:fxc_ProposalDetail =
fxc_ProposalDetail(PopUpManager.createPopUp(UIComponent(Application.application), fxc_ProposalDetail, true));
popup.documentDetail = detail;
popup.readOnly = readOnly;
}
Thanks for posting the code. Now I might be able to help.
Where are you handling the close event of the popup? Besure to use something like this:
private function handleCloseEvent():void {
PopUpManager.removePopUp(this);
}
Besides that it appears your problem has to do with the following:
Because a module is loaded into a child domain, it owns class definitions that are not in the main application’s domain. For example, the first module to load the PopUpManager class becomes the owner of the PopUpManager class for the entire application because it registers the manager with the SingletonManager. If another module later tries to use the PopUpManager, Adobe ® Flash® Player throws an exception.
The solution is to ensure that managers such as PopUpManager and any other shared services are defined by the main application (or loaded late into the shell’s application domain). When you promote one of those classes to the shell, the class can then be used by all modules. Typically, this is done by adding the following to a script block:
import mx.managers.PopUpManager;
private var popUpManager:PopUpManager;
The module that first uses the component owns that component’s class definition in its domain. As a result, if another module tries to use a component that has already been used by another module, its definition will not match the existing definition. To avoid a mismatch of component definitions, create an instance of the component in the main application. The result is that the definition of the component is owned by the main application and can be used by modules in any child domain.
see: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-799a.html
for a better understanding of modules.
as suggested before, reusing the popup instead of creating a new one each time seems to have solved the issue.

flex: manipulating flex elements from external action script class

I have a flex project with a mx:Text.
i have a class that is loaded at the beginning of my project and i want this class to enter text in that text element. the id of the text element is "messagePanel" but when i try to type messagePanel.text i get 'Access of undefined property'. how do i resolve the issue?
example
general.FMS3Connect class connects to an adobe flash media server, when it completes connecting i want it to display the even info code of the connection inside a mx:Box, it's id is messageBox.
on my main mxml file i have the following:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[0xFFFFFF,0xAAAAAA]"
xmlns:local="*">
<mx:Script>
<![CDATA[
import general.FMS3Connect;
private var conn:FMS3Connect= new FMS3Connect();
]]>
</mx:Script>
<mx:Text id="messageBox" color="black" text="trying to connect to server..." creationComplete="conn.connect()" >
</mx:Application>
the function connect() for now just has "messageBox.text='test'";
when i execute the application i get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
how do i resolve the issue?
thanks!
Problem is, your FMS3Connect class has to reference to the Text element.
Easiest (but nasty) solution is to pass in a reference to the Text Element to your connect method, you can then reference the element from that.
something like...
<mx:Text id="messageBox" color="black" text="trying to connect to server..." creationComplete="conn.connect( messageBox )" >
public function connect( messageDisplay : Text ) : void {
// do usual connect stuff.
messageDisplay.text = "test";
}
This isn't the nicest solution in the world, connect shouldn't know about the message box really. But it solved your problem!
wait for creationcomplete event

How would I debug Flex 3 databinding?

I'm trying to connect a datagrid to an HTTPService via a simple external XML document, and this is failing. How would I go about debugging where the problem is arising?
I'm using the following:
<mx:HTTPService id = "licenseService" resultFormat="e4x" url="http://localhost/licenseTest.xml" />
with
<mx:DataGrid horizontalCenter="0" width="476" top="50" dataProvider="{licenseService.lastResult.license}">
I'm relatively new to flex, so basic help would be appreciated.
Add result event handler for HTTP Service:
<mx:HTTPService id = "licenseService" resultFormat="e4x" url="http://localhost/licenseTest.xml" result="licenseService_resultHandler(event)" />
And define the handler inside <mx:Script>:
private function licenseService_resultHandler(event:ResultEvent):void
{
trace("Result:", event.result);
}
You can place a breakpoint inside this method and start debugging the data that comes from the server

Passing array from flex to php

I have a TextInput and a List in my application. I want to send the information written in TextInput and the names of the selected options from the list to a php file.
Following HTTPService sends the TextInput's text and the indices of selected items from list finely to a php file but the selectedItems is not working as i expected. It does not send the names of the selected items
<mx:HTTPService id="configureService" url="configure.php" resultFormat="text" method="POST">
<mx:request xmlns="">
<textInput>
{textInput.text}
</textInput>
<selectedFoodNames>
{foodList.selectedItems.join(",")} <!-- Problem in this LOC -->
</selectedFoodNames>
<selectedFoodIndices>
{foodList.selectedIndices.join(",")}
</selectedFoodIndices>
</mx:request>
</mx:HTTPService>
Now, my php file results:
echo $_POST['textInput']; //Output the right answer
echo $_POST['selectedFoodNames']; //Outputs: "[object Object],[object Object],[object Object]" if three items are selected from the list
echo $_POST['selectedFoodIndices']; //Outputs the indices of selected items separated by comma
The list look like:
<mx:List id="foodList" x="26.95" y="54" width="231.55" height="236.9" allowMultipleSelection="true">
<mx:dataProvider>
<mx:Array>
<mx:Object id="Sugar" label="Sugar" data="#FF0000"/>
<mx:Object id="Salt" label="Salt" data="#00FF00"/>
<mx:Object id="Pepper" label="Pepper" data="#0000FF"/>
</mx:Array>
</mx:dataProvider>
Is there a way i can send the labels of the elements in list?
You'll need to write a function to make a list from the objects.
public static function selectedItemsToLabels(list:List):String {
var a:Array = [];
for each(var o:Object in list.selectedItems) {
a.push(o.label);
}
return a.join(",");
}
This is a static function but you can make it a member of a List if you want to extend that class.
I'm not sure if you want to get another framework involved, but I've used Zend AMF as a solution to such problems. It lets you pass Flex and PHP objects back and forth without having to manually create or parse XML intermediaries.
You can read more at:
http://framework.zend.com/manual/en/zend.amf.html

Resources