-
Mourning Morning.
[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
-
Senior Member
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_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); }
- The right of the People to create Flash movies shall not be infringed. -
-
Mourning Morning.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|