A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: What's wrong with my code?!?!

  1. #1
    Ok. I'm developing a product review section on my site, and ive got a listbox for the products, a dynamic text field for the review, and two pushbuttons (one supposedly opens the product site and the other downloads it.) Right now i am trying to give items in the listbox a url so when u click the "product site" button it opens up the site.

    This is the code for the PushButton:

    on (release) {
    site = list.getSelectedItem().Object;
    address = "http://www."+site+".com"
    getURL(address)}

    For a test I used this code on one of my list entries:

    list.addItem("Sample Review", new Object("yahoo"));

    Whenever I press the button, it goes to http://www..com and completely ignores the site code.I am a newbie at coding in actionscript and am frustrated, please help.

  2. #2
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    list.getSelectedItem().Object;

    That is not valid coding. I am not sure what the correct coding would be, but try:
    list.getSelectedItem(Object)

    It is clearly not reading the Object, so it is the part which is wrong.

  3. #3
    thanks alot, ill try that

  4. #4
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    Wait, an on(release) scipt does not work for PushButtons. You have to use a change handler and then create a function for it.

  5. #5
    sry, didnt work
    ne more ideas

  6. #6
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397


    FListBox.getSelectedItem

    Availability

    Flash Player 6.

    Usage

    myListBox.getSelectedItem()

    Parameters None.

    Returns

    An object or undefined.

    Description

    Method; returns the currently selected item as an object with the properties label and data. If more than one item is selected, the method returns the most recently selected item in the list; if no items are selected, the method returns undefined. To retrieve information about all selected items in a multiple-selection list box, use FListBox.getSelectedItems.

    Example


    The following code returns the label of the item currently selected in listBox1.

    trace(listBox1.getSelectedItem().label);

    The following code returns the data or value associated with item currently selected in listBox2.

    trace(listBox2.getSelectedItem().data);

    The following code returns an object containing the label and the data value associated with the item currently selected in listBox3.

    trace(listBox3.getSelectedItem());


  7. #7
    ok. The stuff u said did actually make sense to me (most stuff doesn't). But now im not sure where to go with the coding. I dont kno much about this stuff, so please try and use lamens terms lol. Thanks

  8. #8
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    on (release) {
    site = list.getSelectedItem().data;
    address = "http://www."+site+".com"
    getURL(address)
    }

  9. #9
    ok somethin isnt working but its prolly my brain.
    Heres the code for that entire part. Its very messy cuz i borrowed code from a tutorial so it looks ****ty, b/c each month would b used for a review. Newayz, heres the code:

    list.addItem("Sample Review", new Date(2, 2), new Object("yahoo"));

    month = ["January", "February", "This is a sample", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    function displayDetails(c) {
    textbox.text = c.getSelectedItem().label+" :";
    var j = c.getSelectedItem().data;
    textbox.text += "\n"+" "+month[j.getMonth()];
    }

    list.setChangeHandler("displayDetails");

    AND THE CODE FOR THE BUTTON:

    on (release) {
    site = list.getSelectedItem().data;
    address = "http://www."+site+".com"
    getURL(address)
    }

  10. #10
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    I don't think you can have 2 data values for a listBox item. I think this because I did not find a variable with yahoo in the variables when SWF was compiled.

  11. #11
    i thought about that, but ive tried deleting the date part of the data temporarily, and nothing changes. What do I do now?

  12. #12
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Don't know about the first part of your script, but this part...

    on (release) {
    site = list.getSelectedItem().data;
    //trace(site);
    address = "http://www."+site+".com"
    getURL(address);
    }

    ...Works fine for me, and does open up (and trace!) yahoo, assuming I've tested it with 2 items (item1 & item2) and 2 datas (yahoo & yahoo), manualy set in the listbox fields.

    You sure your list box has the instance name of list?

  13. #13
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    Originally posted by Novel_Idea87
    i thought about that, but ive tried deleting the date part of the data temporarily, and nothing changes. What do I do now?
    You must be doing something wrong, because I removed the Date stuff and it worked fine.

    This script works:

    list.addItem("Sample Review", new Object("yahoo"));

    month = ["January", "February", "This is a sample", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    function displayDetails(c) {
    textbox.text = c.getSelectedItem().label+" :";
    var j = c.getSelectedItem().data;
    textbox.text += "\n"+" "+month[j.getMonth()];
    }

    list.setChangeHandler("displayDetails");




    on (release) {
    site = list.getSelectedItem().data;
    address = "http://www."+site+".com"
    getURL(address)
    }


    Notice, no new Date(2, 2)

  14. #14
    Could u please send me the source file that u are using cuz i have copy and pasted the code that u posted into my flash file after i wiped out the existing code. And it still wont work. Thanks and sorry for my incompetence

  15. #15
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    http://nerdinside.d2g.com/listBox-fla.fla

    You are of course selecting Sample Review in the listBox BEFORE hitting the button, right?

  16. #16
    the reason urs workd was prolly because ur using a button symbol whereas im using a pushbutton

  17. #17
    mine works with a regular button, i just need to kno how to modify my code for a pushbutton

  18. #18
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    You are scripting the push button wrong, I am suprised it worked at all!!!!!

    This is how to script a push button. First, give it a Change Handler of myButton. Then add this to the first frame of your movie:

    function myButton() {
    site = list.getSelectedItem().data;
    address = "http://www."+site+".com";
    getURL(address);
    }



    Check the source code again. I updated it to work WITH the PushButton. Next time, know how to script a PushButton.

  19. #19
    and now i need to kno how to put code back in so that when i select the item the review comes up in a dynamic textbox, which i had bfore the button issue. so basically i can get both aspects of this to work, just not simultaneously, and i need to kno how. Thank you.

  20. #20
    NerdInside's Avatar
    Join Date
    May 2001
    Location
    Penguin Island
    Posts
    3,439
    I don't think you can. I believe items in listBoxes can only have 1 data value, as I explained before the no variable "yahoo" is set with the old coding.

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