A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8]Dynamic ComboBox Trouble!

  1. #1
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22

    [F8]Dynamic ComboBox Trouble!

    A friend and I are working on a script to load news articles into forms so that they can be edited. We are using a drop box to select the title of the news article, and then use variables to display all the other information, using a MySQL database. Here is the code so far:
    Code:
    //populating the combobox "dropDown"
    
    function AddItems(){
    	for (i=0; i<NumItems; i++){
    		var Name = eval("Name"+i);
    		var TextData = eval("TextData"+i);
    		var Author = eval("Author"+i);
    		var TheDate = eval("TheDate"+i);
    		dropDown.addItem(Name, TextData, Author, TheDate);
    	}
    	dropDown.setChangeHandler("SelectItem");
    }
    //loading variables into text boxes "newstitle_input" and "newstxt_input"
    function SelectItem(){
    	text.newstitle_input = dropDown.getSelectedItem().label;
    	text.newstxt_input = dropDown.getSelectedItem().data;
    	text.date_dyn = dropDown.getSelectedItem().TheDate;
    	text.author_dyn = dropDown.getSelectedItem().Author;
    }
    I believe the trouble is starting in the dropDown.addItem line. We use name for the label, and TextData for the data, but I am not sure how to load more than just these two pieces of information into the combobox. As you can see further down, I try to call up the selected Author and TheDate variables to display them in dynamic text boxes, but I'm sure I have the code wrong, because nothing is working so far, and my pals PHP script is looking pretty good.

    So to sum it up how do I get the combobox to display all these variables I have? Any help would be awesome, thanks.

  2. #2
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    So I answered my initial question thanks to a helpful tutorial but my combobox is still not being populated! Perhaps my script is perfect and maybe it's the PHP that is messed up? I'm just looking for someone to tell me if my code looks alright now.

    Functions Code
    Code:
    //populating the combobox "dropDown"
    
    function AddItems(){
    	for (i=0; i<NumItems; i++){
    		var Name = eval("Name"+i);
    		var TextData = eval("TextData"+i);
    		var Author = eval("Author"+i);
    		var TheDate = eval("TheDate"+i);
    		var ListBoxData = {Name: Name, TextData: TextData, Author: Author, TheDate: TheDate}
    		dropDown.addItem(Name, ListBoxData);
    	}
    	dropDown.setChangeHandler("SelectItem");
    }
    //loading variables into text boxes "newstitle_input" and "newstxt_input"
    function SelectItem(){
    	text.newstitle_input = dropDown.getSelectedItem().label;
    	text.newstxt_input = dropDown.getSelectedItem().data["TextData"]
    	text.date_dyn = dropDown.getSelectedItem().data["TheDate"]
    	text.author_dyn = dropDown.getSelectedItem().data["Author"]
    }
    Loader Actions code

    Code:
    _root.Go = "";
    
    _root.Thinking.gotoAndPlay(2);
    
    loadVariables("newsprocess.php", this);
    The Thinker, once told to go to frame 2, will begin playing and check if variable "Go" is set to "Yes" by PHP. Once it is, Thinker will execute the AddItems function.

    Thanks for any replies.

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    var myVar:LoadVars = new LoadVars
    myVar.onLoad = function(){
    //deal with your PHP return here try using traces to make sure your getting back what you should be
    }
    myVar.sendAndLoad("newsprocess.php", myVar);

    if i had to guess theres nothing comming back from the PHP or at least not what you want.

    (you could probably just do myVar.load("url") )

    [edit] where are you setting go to true or whatever?

  4. #4
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    The value of Go is sent by the PHP script once it has finished executing, letting Thinking know it can run the AddItems function. What is so different about using LoadVars like that as opposed to my loadVariables script? I will try to figure out a way to trace though.

  5. #5
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    function AddItems(){
    for (i=0; i<NumItems; i++){
    trace(eval("Name"+i));
    var Name = eval("Name"+i);
    var TextData = eval("TextData"+i);
    var Author = eval("Author"+i);
    var TheDate = eval("TheDate"+i);
    var ListBoxData = {Name: Name, TextData: TextData, Author: Author, TheDate: TheDate}
    dropDown.addItem(Name, ListBoxData);
    }
    dropDown.setChangeHandler("SelectItem");
    }

  6. #6
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    Alright looks easy enough, the problem is, the script needs to communicate with the database, so it has to be on the net, and when I view the .swf on the net, I don't think the traces have anywhere to show up.
    [edit]
    May I also add that the name of one of the news articles is now showing up in the drop box, but when it is selected none of the variables are loaded.
    Last edited by pyramidhead; 12-05-2006 at 09:27 PM.

  7. #7
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    the SWF doesnt have to be on the net I dont think...just the PHP
    loadVariables("http://somesite/somePHP.php")

    tbh I dunno ive never used the loadVariables command just the load Vars Command
    but I do know PHP cant pass back objects or arrays.

  8. #8
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    Oh duh... I'm an idiot.

    However now it isn't even loading the variables. I don't think it's even connecting to the database when I try to test it via flash.
    [edit]
    I doubt that the PhP script can send the variables back to the .swf when it is not online as well... seems to be some trouble communicating here.
    Last edited by pyramidhead; 12-05-2006 at 09:34 PM.

  9. #9
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    Well we decided it is most likely an error in the PHP script because the variables were being exported incorrectly. However, it is difficult to tell because we both may have errors in our scripts making it impossible to know who's at fault! However, if you think my script looks good than hopefully we can get the PHP worked out, thanks a lot for the replies.

  10. #10
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    try stepping through it one piece at a time

    try using loadVars instead of loadVariables or whatever(that may or maynot make a difference)

    in the loadVars.onLoad handler do a trace for everything being returned like
    Code:
    for(key in this){
         trace(key+ "  =   "+this[key]
    }
    maybe just go to the php page in a webrowser and see what the output is.

  11. #11
    Huh, Radio.
    Join Date
    Nov 2006
    Location
    IL
    Posts
    22
    Yeah we seem to have the PHP output fine now but I will have to try some of your suggestions now, cause it seems that the problem is on my end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center