Hi- I thought this looks pretty good but the data won't go in the list.
this is what php prints for raw data and its code looks like I hope you can give me a tip it passes it to the f12 console from PhP but doesn't populate the list. a BIG thanks for any assistance, j. http://127.0.0.1:8000/test.php?param1=foo¶m2=bar {"foo":"some_value","bar":"another_value"} <?php // Enable CORS headers header("Access-Control-Allow-Origin: *"); // Allow all origins, or set specific origins like 'http://127.0.0.1' header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); header("Access-Control-Allow-Headers: Content-Type, Authorization"); header("Access-Control-Allow-Credentials: true"); // Define the class (similar to your original example) class MyClass { private $foo; private $bar; public function __construct($foo, $bar) { $this->foo = $foo; $this->bar = $bar; } public function toJson() { return json_encode([ 'foo' => $this->foo, 'bar' => $this->bar, ]); } } // Create an instance of MyClass $myClass = new MyClass('some_value', 'another_value'); // Send the object as a JSON response header('Content-Type: application/json'); echo $myClass->toJson(); So far I have thus in actionscript: in f12 mode firefox http://127.0.0.1:8000/test.php?param1=foo¶m2=bar XHRGET http://127.0.0.1:8000/test.php?param1=foo¶m2=bar [HTTP/1.1 200 OK 1ms] foo "some_value" bar "another_value" 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(); 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); 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 { 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 service.addEventListener(ResultEvent.RESULT, onResult); service.send(); } private function onResult(event:ResultEvent):void { // 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 = []; // 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}); } // 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 trace("List data populated:", list.dataProvider.source); } private function onChange(event:Event):void { trace("Selected: " + event.target.selectedItem); } } } Sent with Proton Mail secure email.
