A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Combobox duplicates entries

  1. #1
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194

    resolved [RESOLVED] Combobox duplicates entries

    I am having an issue with a combobox.

    Everything seems to work fine until I click on the "home" link. Then the box duplicates the items in the list.

    I tried to write a function that would add the items on the initial load thinking the addItem code was running again when it enters frame1. Maybe I am still doing it wrong.

    Here is the code:
    Code:
    stop();
    
    import fl.data.DataProvider;
    import fl.events.ComponentEvent;
    import flash.events.Event;
    
    var listBuilt:Boolean = false;
    
    stage.addEventListener(Event.ENTER_FRAME, buildList);
    
    function buildList (evt:Event): void {
    	if (listBuilt == false) {
    		// Add Item to List.
    		my_cb.addItem({data:1, label:"Home"});
    		my_cb.addItem({data:2, label:"First Link"});
    		my_cb.addItem({data:3, label:"Second Link"});
    		listBuilt = true;
    	} else {
    		//do nothing
    	}
    }
    
    // Add Listener.
    my_cb.addEventListener (Event.CHANGE, getData);
    
    function getData(evt:Event): void {
    	gotoAndPlay(evt.currentTarget.selectedItem.data);
    }
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Change this line var listBuilt:Boolean = false;
    to var listBuilt:Boolean;

    It is better to remove the eventlistener once it is built
    PHP Code:
    var listBuilt:Boolean;
    if (
    listBuilt == false)
    {
        
    stage.addEventListener (Event.ENTER_FRAMEbuildList);
    }

    function 
    buildList (evt:Event):void
    {
        
    // Add Item to List.
        
    my_cb.addItem ({data:1label:"Home"});
        
    my_cb.addItem ({data:2label:"First Link"});
        
    my_cb.addItem ({data:3label:"Second Link"});
        
    listBuilt true;
        
    stage.removeEventListener (Event.ENTER_FRAMEbuildList);

    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Mourning Morning. groupof1's Avatar
    Join Date
    Feb 2008
    Location
    Middle of somewhere
    Posts
    194

    That did it!

    Thank you for the assistance, it works like a charm. I knew there was something simple I was missing. Now I can expand upon this.

    I am a graphic designer and can muck my way through some code, but I'm not very proficient yet. I mainly rely on books and forums. (Flashkit is my personal favorite.)

    Just for clarity and for the sake of others, here is the final working code:
    Code:
    stop();
    
    import fl.data.DataProvider;
    import fl.events.ComponentEvent;
    import flash.events.Event;
    
    var listBuilt:Boolean;
    
    if (listBuilt == false)
    {
    	stage.addEventListener(Event.ENTER_FRAME, buildList);
    }
    
    function buildList (evt:Event): void 
    {
    		// Add Item to List.
    		my_cb.addItem({data:1, label:"Home"});
    		my_cb.addItem({data:2, label:"First Link"});
    		my_cb.addItem({data:3, label:"Second Link"});
    		listBuilt = true;
    		stage.removeEventListener(Event.ENTER_FRAME, buildList);
    }
    
    // Add Listener.
    my_cb.addEventListener (Event.CHANGE, getData);
    
    function getData(evt:Event): void {
    	gotoAndPlay(evt.currentTarget.selectedItem.data);
    }
    What the world needs now is a nice hot bath.
    _________________________________________________
    Battles: Silverx2

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