Jorge Llerena 0 Posted December 1, 2011 Report Share Posted December 1, 2011 Dear Larry, I recently got your book and eagerly read it (I've read and tried 7 chapters in 3 days). I knew Flex when version 3 was in beta, but never programmed anything. I've just finished chapter 8 and tried to bind the drop down list showing the Departments using a simple query to the database in the same fashion you populate the grid with the employees. The PHP file i'm using is (getDepartments.php): <?php header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="utf-8" ?><departments>'; require_once('mysql.inc.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, 3306); if ($dbc) { $q = "SELECT * from departments ORDER by 1"; //printf("\n%s",$q); $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo "<department> <id>{$row['id'] }</id> <Name>{$row['name'] }</Name> </department> ";} // End of WHILE loop } // End of mysqli_num_rows( ) IF } // End of $dbc IF echo '</departments>'; ?> Inside the declarations section I declare: <s:HTTPService id="getDepartmentsService" url="http://localhost/~Jorge/flex4ch08/getDepartments.php" method="GET" resultFormat="e4x" result="getDepartmentsResult(event)" fault="serviceFault(event)"> </s:HTTPService> I included the script: private function getDepartmentsResult(event:ResultEvent):void { departmentsList= event.result.department; } And in the MXML application I tried: <mx:FormItem label="Department"> <s:DropDownList id="employeeDepartment" dataProvider="{departmentsList}" labelField="name" prompt="Select one:"></s:DropDownList></mx:FormItem> And keep getting the error: 1067: Implicit coercion of a value of type XMLList to an unrelated type mx.collections:IList I thought I was very clever trying to replace the hardcoded list you included with this query which is now giving me headaches. Can you help me? Quote Link to post Share on other sites
Jorge Llerena 0 Posted December 2, 2011 Author Report Share Posted December 2, 2011 I'm sorry, It is not a web service, but rather an HTTPService... Quote Link to post Share on other sites
Larry 433 Posted December 2, 2011 Report Share Posted December 2, 2011 Thanks for the interest in the book. Could you confirm the version of Flex you're using? Also, you could formally perform the coercion: departmentsList= event.result.department; as IList And is there a benefit to creating a function that assigns the result to a variable rather than use the specific property of the result as the dataprovider? Quote Link to post Share on other sites
Matt 27 Posted January 23, 2012 Report Share Posted January 23, 2012 Larry, I have been working on this chapter as well, and although I haven't ran into any trouble, I still am curious about the following: And is there a benefit to creating a function that assigns the result to a variable rather than use the specific property of the result as the dataprovider? private function getDepartmentsResult(event:ResultEvent):void { departmentsList= event.result.department; } If that was the line you were referring to, it comes straight out of your book (pg. 249). Why is it not beneficial to do it this way? I would think it's better separation of code. Quote Link to post Share on other sites
Larry 433 Posted January 24, 2012 Report Share Posted January 24, 2012 D'oh! I wasn't looking at that in context. Nevermind... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.