Hi there

Im working on a listbox(flash component), where upon click, will display other arrays in a movie( which is also a listbox made from textfield). The second listbox suppose to contain html links, where it will open up a popup upon clicked.

The problem is that whenever i click on the listbox, the content in the sub listbox doesn't change. that is, it doesnt empty the previous load of links, but just add on to the list of links.

Im not sure what i can use to prevent this issue. I have tried listener, and "if else" statements.. Im not sure what else can be done to prevent this.

I've include the codes for the 2nd listbox(the textfield listbox) Hope that helps better in the understanding of my queston.

Really appreciate any help. Thanks.

var ListListen:Object = new Object();
ListListen.change = function(pEvent:Object) {
   var selectItem:Object = pEvent.target.selectedItem;
var b :Object = pEvent.target.selectedIndex;
 sampleList =_root.sampleMovie.Slist
sampleList._visible = false;
  for (j=0; j<total; j++) { 
if (fTitle[b]== sampleTitle[j]) {
sampleList._visible = true;
 sampleList.htmlText  += "<A HREF='javascript:openNewWindow(" + sampleLinks[j] + ",myFlash,width=640,height=480,toolbar=no,resizable  =no)' target = '_blank'> " + sampleWorks[j]+ "</a><br>"
 sampleList.dataProvider = selectItem.data;
 
}
}
};

Dani AI

Generated

The symptom here is that the second “listbox” (a TextField used as an HTML list) is being appended to instead of replaced on each click. was right to suggest clearing before repopulating — but the practical pattern that avoids duplication and side effects is: build the new HTML in a temporary string, assign it once to the TextField, reset the scroll, and handle link clicks in ActionScript rather than embedding JS in the href.

Concrete checklist and gotchas:

  • Confirm the control type. If it is a TextField, use htmlText; if it is a List component, clear its dataProvider with the component API. Don’t mix the two styles (TextField has no dataProvider).
  • Avoid appending directly to the field each selection cycle. Build a string variable, then set the TextField’s htmlText once — this clears old content and is faster.
  • Reset the vertical position after assigning: set the text field’s scroll to 1 so the user sees the top.
  • Use TextField onTextLink with href="event:..." anchors to catch clicks in AS and open popups via getURL or a custom handler. This is safer than javascript: URLs and works more reliably across browsers.
  • Declare loop counters and temporaries with var inside functions to avoid accidental globals and cross-call interference. Also ensure your selectedIndex value is valid before indexing arrays.

Example pattern (ActionScript 2 style):

var html:String = "";
for (var i:Number = 0; i < totalItems; i++) {
    if (matchesCategory(i)) {
        html += '<a href="event:item' + i + '">' + titles[i] + '</a><br>';
    }
}
secondaryTF.htmlText = html;
secondaryTF.scroll = 1;

secondaryTF.onTextLink = function(id:String) {
    var idx:Number = Number(id.substr(4)); // "itemN"
    getURL(links[idx], "_blank");
};

If after these changes links still accumulate, check for multiple listeners being attached repeatedly or for an outer routine that repopulates without clearing.

Recommended Answers

All 3 Replies

I am not "pro" in Flash but you may try to do following. After selection from main index been made ad an extra line in your code which will empty your listbox of main index (empty your string variable) and then load up sub index.

hm..
i need to have 2 listbox showing.. so that user uses the main lsitbox to open up whatever it is on the 2nd listbox aka textfield with scrolling buttons..

Same thing

At start your_subindex   = {empty string}
on 1st click your_subindex   = {1st subindex}
on 2nd click 1st command your_subindex   = {empty string}
2nd command your_subindex   = {2nd subindex}

and so on.

Also why dont you try classic on? All subindexes placed on the stage and make them invisible on start. Then when ever any selection made run small script which will make shore that others subindexes are hiden only requered is visible. In style of rollover, instead of rollover use command onclick.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.