# Refresh Listbox

**URL:** <https://forum.kirupa.com/t/refresh-listbox/6505>\
**Category:** Uncategorized\
**Created:** [October 9, 2002, 6:53am UTC](https://forum.kirupa.com/t/refresh-listbox/6505 "2002-10-09T06:53:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![waffe](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@waffe](https://forum.kirupa.com/u/waffe)\
**Post date:** [October 9, 2002, 6:53am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/1 "2002-10-09T06:53:25Z")

</div>

What would be the easiest way to refresh a list box to its original state after some items have been erased.

Anyone----

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:01am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/2 "2002-10-09T07:01:21Z")

</div>

Hmm, just another theory but…

Try creating the state as an AS function or prototype. Then call it on load to populate the box. Then have a reset button that calls the function again and resets the state of the listbox.

Worth a shot I suppose.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:05am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/3 "2002-10-09T07:05:36Z")

</div>

What is an AS function or prototype?  
Better yet, how about a tutorial.

I’ll take a peek.:sleep:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:07am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/4 "2002-10-09T07:07:31Z")

</div>

There is a tutoral on prototypes in the AS tricks section.

Just go to [www.kirupa.com](http://www.kirupa.com) and click on Actionscript. I think it is the first link in the Actionscripts section.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:13am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/5 "2002-10-09T07:13:19Z")

</div>

Can you post a .fla so I can see what I can do?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:31am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/6 "2002-10-09T07:31:13Z")

</div>

the fla is 240k and I guess that’s to big to upload and I can not upload swf.☹ What to do? but start reading.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:32am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/7 "2002-10-09T07:32:12Z")

</div>

Well good luck. I am off to bed now. 3:30 in the AM here.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 7:34am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/8 "2002-10-09T07:34:31Z")

</div>

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 3:20pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/9 "2002-10-09T15:20:57Z")

</div>

```auto

function populate(){
	box1.removeall();
	box1.additem("apple");
	box1.additem("orange");
	box1.additem("mango");
	box1.additem("pear");
}

```

then on a button…

```auto

on(release){
populate();
}

```

Are you posting questions on these topics under different names?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 5:14pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/10 "2002-10-09T17:14:01Z")

</div>

Yeah, I noticed questions about the same exact thing but from all different names. I got confused…haha.

If you don’t mind if I change the subject for a second…

Hey Montoya, how come whenever I write a function exactly like the above and call it, it never works. I end up rewriting it as a prototype and all works fine and dandy. I don’t get it… any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 6:35pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/11 "2002-10-09T18:35:25Z")

</div>

good question… why don’t you write one that is not working and let me see it. Perhaps we can solve it together.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 8:42pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/12 "2002-10-09T20:42:49Z")

</div>

Ok, it is probably some really stupid mistake on my part though.

Let us try this basic way…

I add this code onto my movie clip.

```auto
onClipEvent (enterFrame) {
	this.slide();
}

```

And the non-working function (this is a basic one for easier explanation)

```auto
function slide() {
	this._x += 1;
};

```

The above does not work, but when I change it to the below, it works perfectly…

```auto
MovieClip.prototype.slide = function() {
	this._x += 1;
};

```

I did nothing but change it from a function to a prototype. I didn’t even change the code on the movie clip.

Any ideas? Can you not += in a function maybe?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 9:41pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/13 "2002-10-09T21:41:45Z")

</div>

well…this is how I would do it… don’t know if it is the best method, but it works for me

for mc

```auto

onClipEvent(enterframe){
	_root.slide(this);
	
}

```

the function itself:

```auto

function slide(mc){
	mc._x+=1;
}

```

try it out…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 9:45pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/14 "2002-10-09T21:45:09Z")

</div>

'DOH!!!

Works great! Thanks Montoya, I told you it would probably be some stupid mistake.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 10:06pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/15 "2002-10-09T22:06:17Z")

</div>

No problem, brotha!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 10:16pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/16 "2002-10-09T22:16:46Z")

</div>

Ready for another home-made explanation, Lost? 😛

No, this is really simple this time: it’s just that this.slide is the way you call a prototype, not a function. Functions don’t apply to an object, so Flash doesn’t know who **this** is.

The function takes the clip as a parameter, so it knows who it is talking to.

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 9, 2002, 10:27pm UTC](https://forum.kirupa.com/t/refresh-listbox/6505/17 "2002-10-09T22:27:06Z")

</div>

ohhhhhhhhhhhhhhh.

All this time I thought there was just something wrong with my Flash program (I actually tried reinstalling it because I just couldn’t get it to work…I know I am lame).

With the method Montoya showed me it made perfect sense to define the mc in the function you are calling (function slide(mc)).

I can’t believe I didn’t think of that earlier.

'DOH!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 10, 2002, 12:42am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/18 "2002-10-10T00:42:16Z")

</div>

Well said, Pom… Lost, Im sorry if I didnt explain that puppy further…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 10, 2002, 1:31am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/19 "2002-10-10T01:31:41Z")

</div>

Nah, I got the basic jist from what you showed me. Ilyas just went further down and compared it to prototypes.

Now I can stop using prototypes for EVERYTHING…haha.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 10, 2002, 8:10am UTC](https://forum.kirupa.com/t/refresh-listbox/6505/20 "2002-10-10T08:10:54Z")

</div>

> \*Originally posted by ilyaslamasse \*  
> **Functions don’t apply to an object, so Flash doesn’t know who this is.**  
> Well, that’s not exactly the reason why it’s not working, actually. The true reason [SIZE=1]I think[/SIZE] is that Flash is looking for a function declared in this, whereas the function was declared in the \_root.

My bad.

pom :cowboy:

[Next page](https://forum.kirupa.com/t/refresh-listbox/6505.md?page=2)
