Hi all-
This code doesn't seem to want to fire onResult function after adding
the event listener service.addEventListener(ResultEvent.RESULT, onResult);
It is kind of a show stopper.
If i call a mock test in the code below from the constructor it worked, but if
it is executing where all the service stuff is ...
in fetchdata it is not picking up the listener and running with it going to the
onResult function.
The test value "go3" only gets called when running a test in the constructor
and not when i add the eventlistener and run the service.
I saw an issue with amfphp with royale and an open issue don't know if the 2
are related #119
It is really kind of technical for me to know for sure.
thanks,
j.
package testpkg {
import org.apache.royale.core.UIBase;
import org.apache.royale.html.elements.Button;
import org.apache.royale.events.MouseEvent;
import org.apache.royale.net.HTTPService;
import org.apache.royale.net.events.ResultEvent;
import org.apache.royale.net.events.FaultEvent; // Import FaultEvent for
error handling
import org.apache.royale.jewel.List;
import org.apache.royale.collections.ArrayList;
import org.apache.royale.jewel.Alert; // Import Alert for showing messages
import org.apache.royale.events.Event;
import org.apache.royale.jewel.Grid;
import org.apache.royale.jewel.GridCell;
import org.apache.royale.html.elements.H3;
import org.apache.royale.html.beads.layouts.Paddings;
import org.apache.royale.jewel.Card;
import org.apache.royale.jewel.supportClasses.card.CardHeader;
import org.apache.royale.jewel.supportClasses.card.CardPrimaryContent;
public class SqliteQuery extends UIBase {
public var _listData:ArrayList= new ArrayList(["Blueberries",
"Bananas", "Lemons", "Oranges", "This is a long item render to try long texts"
]);;
private var list:List = new List();
[Bindable]
public function get listData():ArrayList {
return _listData;
}
public function set listData(value:ArrayList):void {
_listData = value;
}
public function SqliteQuery() {
// Initialize listData as ArrayList
super();
testOnResult();
var grid:Grid = new Grid();
grid.gap = true;
grid.itemsVerticalAlign = "itemsSameHeight";
var paddings:Paddings = new Paddings();
paddings.paddingTop = 0;
paddings.paddingLeft = 50;
paddings.paddingRight = 50;
paddings.paddingBottom = 50;
grid.addBead(paddings);
var card:Card = new Card();
var cardHeader:CardHeader = new CardHeader();
var headerText:H3 = new H3();
headerText.text = "Default";
headerText.className = "primary-normal";
cardHeader.addElement(headerText);
card.addElement(cardHeader);
var list:List = new List();
list.id = "list1"; // Use `id` instead of `localId`
list.width = 200;
list.height = 300;
list.selectedIndex = 2;
list.dataProvider = listData;
list.addEventListener("change", onChange);
list.addEventListener("error",onError);
//listData = new ArrayList();
// Apply a border style to the List
list.className = "listBorderStyle"; // Link the CSS class to the List
// Add the scrolling beads for horizontal and vertical scrolling
//list.addBead(new HorizontalListScroll()); // For horizontal
scrolling
// list.addBead(new VerticalListScroll()); // For vertical
scrolling
var cardPrimaryContent:CardPrimaryContent = new
CardPrimaryContent();
cardPrimaryContent.addElement(list);
card.addElement(cardPrimaryContent);
var gridCell:GridCell = new GridCell();
gridCell.desktopNumerator = 1;
gridCell.desktopDenominator = 2;
gridCell.tabletNumerator = 1;
gridCell.tabletDenominator = 2;
gridCell.phoneNumerator = 1;
gridCell.phoneDenominator = 1;
gridCell.addElement(card);
grid.addElement(gridCell);
addElement(grid);
}
public function getld():ArrayList {
return listData;
}
// Fetch data and populate listData
public function fetchData():void {
Alert.show("go2");
var service:HTTPService = new HTTPService();
//service.method="POST";
//service.url = "http://127.0.0.1:8000/test.php";
service.contentType = "application/json"; // For JSON requests
service.url =
"http://127.0.0.1:8000/test.php?param1=foo¶m2=bar";
service.method = "GET"; // Use GET for query parameters
Alert.show("Before adding listener");
service.addEventListener(ResultEvent.RESULT, onResult);
Alert.show("Listener added");
service.send();
Alert.show("Service sent"); // Check if this line is being executed
}
private function onResult(event:ResultEvent):void {
Alert.show("go3");
Alert.show("Result received: " + event.data.toString()); // Inspect
the result
// The response data is a JSON object with foo and bar properties
var responseData:Object = event.data;
// Array to hold the new items to add to the List
var items:Array = ["foo"];
Alert.show("test1");
// Loop through the response data (assuming it's an array of objects)
for (var i:int = 0; i < responseData.length; i++) {
var item:Object = responseData[i];
// Create a new object with the foo and bar properties
items.push({foo: item.foo, bar: item.bar});
}
Alert.show("test2");
// Now set the items array to the List's dataProvider
// Use list.dataProvider directly, and make sure to use an ArrayList
list.dataProvider = new ArrayList(items);
// Optional: Log the data to verify
Alert.show( list.dataProvider.source);
}
private function onChange(event:Event):void {
Alert.show("Selected: " + event.target.selectedItem);
}
private function onError(event:ErrorEvent):void {
Alert.show("Error occurred: " + event.toString());
}
private function testOnResult():void {
var resultEvent:ResultEvent = new ResultEvent(ResultEvent.RESULT, false,
false, "Mock Result");
onResult(resultEvent); // Directly trigger onResult with mock data
}
}
}
Sent with Proton Mail secure email.