Solved

Dynamically loading data into the drop down box

Posted on 2003-12-02
13
576 Views
Last Modified: 2010-04-03
I have a UI componant (combo box) and I want to be able to load the list from a text file.
Is this possible? If so, how?
The other thing I need is to be able to send the selection from the combo box into a mysql database. I have set up a php page that sends the data from my text boxes to the database, so really all I need is to know how to send it to php.
I hope this makes sense, if not I'll try and explain better. Just let me know.

Cheers

-OBCT
0
Comment
Question by:OBCT
  • 8
  • 4
13 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9857955
Create a "combodata.xml" xml file, and write in it:

<?xml version="1.0" encoding="UTF-8"?>
<combodata>
      <item label="First Label"      data="first" />
      <item label="Second Label"      data="second" />
      <item label="Third Label"      data="third" />
      <item label="Fourth Label"      data="fourth" />
      <item label="Fifth Label"      data="fifth" />
      <item label="Sixth Label"      data="sixth" />
</combodata>

then, in your movie, call your combobox, for example, "combo_cb", and drop this code on the same frame:

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if(ok){
            var nodes = this.firstChild.childNodes;
            for(var i = 0; i < nodes.length; i++){
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      this.yourVariable = _cb.getSelectedItem().data;
}
data_xml.load("combodata.xml");



with this code, when you change the selected item, the "yourVariable" variable is created in the same timeline where the combo lies, holding the selected item data.
If you want to create it in a loadVars instance, change the code to:

data_var = new LoadVars();

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if(ok){
            var nodes = this.firstChild.childNodes;
            for(var i = 0; i < nodes.length; i++){
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      data_var.yourVariable = _cb.getSelectedItem().data;
}
data_xml.load("combodata.xml");


Now, when you send you data to php (you know how, if you send data from textfields), you get that variable with:

$_POST['yourVariable']
0
 
LVL 9

Author Comment

by:OBCT
ID: 9858811
Ok I've done that and its working fine.
I just have to more questions....

1) How can I adjust the width of the combo box?

2) I was intending on using LoadVars to send the data to my php page seeing the rest of my data is sent that way, but....
how to I get flash to get the variable the user has selected?  e.g. a text box uses      newVars.txt_1 = txt_1.text       so what would/should I use for the combo box?

Cheers

-OBCT
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 9859772
your combo box will automatically adjust to the max item size...  so you don't have to worry about that...

you can use loadvars if you want...

you would just send that information in the changeData function above....  like this:

function changeData(_cb)
{
    myData = new LoadVars();
    myData.yourVariable = _cb.getSelectedItem().data;
    myData.sendAndLoad("/yourpage.php", myData, "POST");
    myData.onLoad = function(success){
        if(success){
           trace("successful transaction");
        } else {
           trace("an error occured in the transaction");
        }
    };
}


I believe, that is all you need...  then you would collect the "yourVariable"  using the method posted above by Negatyve....


hope that helps to clarify...


rp
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 9

Author Comment

by:OBCT
ID: 9887160
I tried adding the loadvars in my on release function, but now I'm having three problems.
1) The username and email are not being submited to my db anymore
2) The combo box didn't adjust its width automatically
3) In the database, in the column that contains my variable from the combo box, it says undefiend.

What did I do wrong??
0
 
LVL 9

Author Comment

by:OBCT
ID: 9891718
Sorry about those errors, they were my own little errors which I have fixed up now.
However, in my database I am still getting "undefiend" in the column that is meant to hold the value from my text box.
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9902250
it should be:

$_POST['textfield_associated_variable']
0
 
LVL 9

Author Comment

by:OBCT
ID: 9902302
This is the code I am using, and it wont send anything into my database. The way I had it working before was using loadVariablesNum with the GET method...
any suggestions?

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
     this.path.combo_cb.setEnabled(true);
     if(ok){
          var nodes = this.firstChild.childNodes;
          for(var i = 0; i < nodes.length; i++){
               this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
          }
          this.path.combo_cb.setChangeHandler("changeData");
          this.path.changeData(combo_cb);
     } else {
          this.path.combo_cb.addItem("no data found");
          this.path.combo_cb.setEnabled(false);
     }
};
function changeData(_cb)
{
     this.newUser = _cb.getSelectedItem().data;
}
data_xml.load("http://www.dfgsgsdfgsdfg.com/xml/combodata.xml");

submitBTN.onRelease = function() {
      if (!username.length) {
            status = "Please enter a username"
      } else {
            if (!email.length or email.indexOf("@") == -1 or email.indexOf(".") == -1 or email.indexOf("com") == -1) {
                  status = "Please enter a valid email"
            } else {
                  if (email.length < 7) {
                        status = "Please enter a valid email"
                  } else {
                        status = "Loading...Please wait..."
                        var newUser = new LoadVars()
                        newUser.username = _root.username
                        newUser.email = _root.email
                        newUser.timeZone = _root._cb.getSelectedItem().data
                        newUser.load("http://www.dfgsfgsdfg.com/scripts/register.php", 0, "POST")
                        newUser.onLoad = function(success) {
                              if (success) {
                                    status = "Complete"
                              } else {
                                    status = "Error"
                              }
                        }
                  }
            }
      }
}
0
 
LVL 9

Author Comment

by:OBCT
ID: 9910583
Can someone please help!
0
 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
ID: 9912877
try it:

combo_cb.setEnabled(false);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.path = this;
data_xml.onLoad = function(ok)
{
      this.path.combo_cb.setEnabled(true);
      if (ok) {
            var nodes = this.firstChild.childNodes;
            for (var i = 0; i < nodes.length; i++) {
                  this.path.combo_cb.addItem(nodes[i].attributes.label, nodes[i].attributes.data);
            }
            this.path.combo_cb.setChangeHandler("changeData");
            this.path.changeData(combo_cb);
      } else {
            this.path.combo_cb.addItem("no data found");
            this.path.combo_cb.setEnabled(false);
      }
};
function changeData(_cb)
{
      this.newUser = _cb.getSelectedItem().data;
}
data_xml.load("http://www.dfgsgsdfgsdfg.com/xml/combodata.xml");
submitBTN.onRelease = function()
{
      if (!this._parent.username.length) {
            this._parent.status = "Please enter a username";
      } else {
            if (!this._parent.email.length ||
                  this._parent.email.indexOf("@") == -1 ||
                  this._parent.email.indexOf(".") == -1 ||
                  this._parent.email.indexOf("com") == -1) {
                  this._parent.status = "Please enter a valid email";
            } else {
                  if (this._parent.email.length < 7) {
                        this._parent.status = "Please enter a valid email";
                  } else {
                        this._parent.status = "Loading...Please wait...";
                        this._parent.newUser = new LoadVars();
                        this._parent.newUser.path = this._parent;
                        this._parent.newUser.username = this._parent.username;
                        this._parent.newUser.email = this._parent.email;
                        this._parent.newUser.timeZone = this._parent.combo_cb.getSelectedItem().data;
                        this._parent.newUser.onLoad = function(success)
                        {
                              if (success) {
                                    this.path.status = "Complete";
                              } else {
                                    this.path.status = "Error";
                              }
                        };
                        this._parent.newUser.sendAndLoad("http://www.dfgsfgsdfg.com/scripts/register.php", this._parent.newUser, "POST");
                  }
            }
      }
};
0
 
LVL 9

Author Comment

by:OBCT
ID: 9913067
I tried that, used $HTTP_POST_VARS on my php script and it didn't add anything into the database.
0
 
LVL 9

Author Comment

by:OBCT
ID: 9913089
I know there isn't anything wrong with my php page because when I try something like this:
http://www.sdlfhs.com/scripts/register.php?username=Blah&email=i_live@themoon.com
it enters it into the db.
0
 
LVL 9

Author Comment

by:OBCT
ID: 9913107
LOL sorry my bad. I forgot to save my php script after I changed everything to HTTP_POST_VARS.
Thanks for all your help, you really are an expert!

Cheers!

-OBCT
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9913127
yeah!! :)

cheers
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Migrate From Flash Media Server 4.5 To IIS Smooth Streaming or VLC 6 1,138
AWAY 3d Using BitMapCubeTexture 1 406
Flash player 17 install script .bat or .vbs 9 539
Flash Converter 8 120
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now