Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 08:31
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  Populate Combo Box + AS3 + PHP + MySQL
0 Members and 3 Guests are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: Populate Combo Box + AS3 + PHP + MySQL  (Read 10261 times)
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« on: 07/02/08, 09:28 »

Hey there-  I successfully learned to save and load data from flash/PHP/MySQL with the tuts on this site, thanks!  So, now I am wondering how I would populate a combo box with data found in the DB?  Any help is appreciated.  Thanks!
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 07/02/08, 13:21 »

First question to spot the problem: you know how to populate the combo trough AS with static data?

Jorge
Logged

worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #2 on: 07/02/08, 15:02 »

Yes.  Here's an example:

ActionScript 3:
Code:
import fl.controls.ComboBox;
import fl.data.DataProvider;

var questions:Array = new Array(
{label:"Your pets name?", data:"five.swf"},
{label:"Your High Schools name?", data:"four.gif"},
{label:"Your shoe size?", data:"three.gif"},
{label:"Your SAT score?", data:"two.gif"},
{label:"Your Mothers name?", data:"one.gif"}
);

userQuestion.dropdownWidth = 210;
userQuestion.prompt = "Pick Your question";
userQuestion.dataProvider = new DataProvider(questions);
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #3 on: 07/03/08, 02:59 »

great:

comboBox.dataProvider=questions;

and youre done Wink
Logged

happy flashing
Cool
Ronald
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #4 on: 07/03/08, 04:31 »

You just need to build the dataProvider with loaded data, i.e following onLoad handler from tutorial

function onDataLoad(evt:Event){
        var 
questions:Array = new Array()
        for(var 
i:uint=0i<evt.target.data.canti++){
           
questions.push({label:evt.target.data["question"+i], data:evt.target.data["movie"+i]})
        }
        
userQuestion.dataProvider = new DataProvider(questions);
    }

This assumes a PHP output like this:

question0=What ....&movie0=some.swf&question1=Where...&movie1=other.swf& ......... &movie10=Which ...&movie10=last.swf&cant=10

Jorge
Logged

worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #5 on: 07/03/08, 07:32 »

Excellent!  Thanks again! 

Also, what if I needed the combo box label to link to a url or a another frame in my movie?

Here's the code that worked for me, incase someone comes across this post:

AS3:
Code:
import fl.controls.ComboBox;
import fl.data.DataProvider;

var myData:URLRequest = new URLRequest("questions.php");
myData.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, questionOnLoad);
loader.load(myData);

function questionOnLoad(evt:Event) {
var questions:Array = new Array();
for (var i:uint=0; i<evt.target.data.cant; i++) {
questions.push({label:evt.target.data["question"+i], data:evt.target.data["image"+i]});
}
questions.dataProvider = new DataProvider(questions);
questions.dropdownWidth = 210;
questions.prompt = "Pick Your Question";
}

stop();

PHP:
Code:
<?php
$connect 
mysql_connect("server""username""password");
$db "your database name";
$table "your table name";
mysql_select_db("$db"$connect);
$result mysql_query("SELECT Questions, Images FROM $table");
$cant 0;
while(
$row=mysql_fetch_array($result)){
echo "question$cant=$row[Questions]&image$cant=$row[Images]&";
$cant++;
}
echo 
"cant=$cant";
?>

« Last Edit: 07/03/08, 07:42 by worked » Logged
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #6 on: 07/04/08, 11:37 »

So i learned to link to a url via a dynamic combo box via navigateToURL(); method.  Question.  What if I wanted to link to a frame or another .swf file?  Thanks for any help!

working url links:
Code:
import fl.controls.ComboBox;
import fl.data.DataProvider;

var myData2:URLRequest = new URLRequest("comboBox.php");
myData2.method = URLRequestMethod.POST;

var loader2:URLLoader = new URLLoader();
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
loader2.addEventListener(Event.COMPLETE, boardReviewsOnLoad);
loader2.load(myData2);

function boardReviewsOnLoad(evt:Event) {
var boards:Array = new Array();
for (var i:uint=0; i<evt.target.data.cant; i++) {
boards.push({label:evt.target.data["title"+i], data:evt.target.data["comments"+i]});
}
boardBox.dataProvider = new DataProvider(boards);
boardBox.dropdownWidth = 210;
boardBox.prompt = "Pick Your Board";
boardBox.addEventListener(Event.CHANGE, changeHandler);
}

function changeHandler(event:Event):void {
       var request:URLRequest = new URLRequest();
       request.url = ComboBox(event.target).selectedItem.data;
       navigateToURL(request);
       boardBox.selectedIndex = -1;
}

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #7 on: 07/04/08, 12:49 »

How about loadMovie()?
Logged

happy flashing
Cool
Ronald
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #8 on: 07/04/08, 14:00 »

If you check navigateToUrl Help entry, you will see that it has a second argument that is the target, put there the name of your frame. Also if the loaded content isn't inside your domain, will fails due to security restriction (needs a crossdomain), check always inside your browser

Jorge
Logged

worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #9 on: 07/05/08, 09:07 »

Thanks for responding Jorge.   I added another frame to my movie and gave it a frame name of 'datagrid' and updated the MySQL URL row to equal the flash movie I'm currently in. Unfortunately adding the frame name to the second argument does not work... for example:

Code:
function changeHandler(event:Event):void {
       var request:URLRequest = new URLRequest();
       request.url = ComboBox(event.target).selectedItem.data;
       navigateToURL(request, 'datagrid');
       boardBox.selectedIndex = -1;

Any other suggestions on how I would get the combo box to advance me to another frame in my movie?  Thanks!
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #10 on: 07/05/08, 09:21 »

navigateToUrl is to open an external link, so frame in this context means an HTML frame. If you want to go to a flash frame with a label, use

gotoAndStop("somelabel")

where somelabel is the frame label

Jorge
Logged

worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #11 on: 07/05/08, 09:59 »

Hey Jorge-  So I have a simple MySQL db with a row that looks like so:
{label:"Something", data:"datagrid"}

When the combo box is populated with the label "Something" and a CHANGE event is applied to it (so it takes me to frame "datagrid" when selected).  How would I alter the CHANGE event from a navigateToURL(); to a gotoAndStop(); for this to work?

Code:
function changeHandler(event:Event):void {
       var request:URLRequest = new URLRequest();
       request.url = ComboBox(event.target).selectedItem.data;
       navigateToURL(request);
       boardBox.selectedIndex = -1;
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #12 on: 07/05/08, 10:11 »

Instead of

navigateToURL(request);

use

gotoAndStop(request)

That's it

Jorge
Logged

worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #13 on: 07/05/08, 10:50 »

Awesome, thanks!
Logged
JKofSpades
Server what's that
*
Posts: 10


View Profile Email
« Reply #14 on: 02/03/10, 10:22 »

 Huh Huh Huh Huh Angry Angry Angry

Hey Guys,

I KEEP getting the Error #1069: Property cant not found on String and there is no default value.

When I try to implement the code.

PLEASE any help would be greatly appreciated.

Thanks
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything