# Using .as files, simple remove button !?

**URL:** https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044
**Category:** Uncategorized
**Created:** [July 3, 2008, 10:02am UTC](https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044 "2008-07-03T10:02:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![VladM](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@VladM](https://forum.kirupa.com/u/VladM)
#### Post date: [July 3, 2008, 10:02am UTC](https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044/1 "2008-07-03T10:02:51Z")

</div>

Hello everyone, I’m pretty new in CS3 and this being my first post, i’ll just be quick (if I can…). My first question is a pretty noobish one, i’ve just started using .as files. \*\*How do I export the working swf \*\*? **It seems when I export the swf like I usually do, it doesn’t recognize the external .as files**. Sorry, but I can’t seem to find any documentation on **using .as files** in the help or on the net. I pretty much figured out everything except this exporting bit. Do I have to use an external program ? None of the publish settings seem to affect this… so how do I do it?

Now to the code question. I’ll just set up the context. I have an external class that extends the movieclip class, i put an instance of the class on the stage using addChild. Now, I want to remove this object when I press a button and put a new one in it’s place (the ideea is that the graphics contain some random stuff generated in the class constructor). It seems pretty simple… yet it dosen’t work.

```auto

var myObject:myClass = new myClass();
addChild(myObject);
myButton.addEventListener(MouseEvent.CLICK, remove);
function remove(e:Event): void {
      removeChild(myObject);
      var myObject:myClass = new myClass();
      addChild(myObject);
}

```

In the remove function, without the last two lines, the code removes the object on the stage, then at the second click on the button, it returns an error, saying: “_The supplied DisplayObject must be a child of the caller._” It’s ok, so he’s trying to remove the object but it’s not on stage anymore. Then I add the last 2 lines, even on the first click on the button the output says: “_Parameter child must be non-null_.” and I guess he’s talking about addChild(myObject). So ok, i comment the last addChild line, and still the same error.I guess there’s a conflict in using the same object name? But then how do I release an object from the memory. I’m kind of lost here.

---

<div class="post-metadata">

### Author: ![VladM](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@VladM](https://forum.kirupa.com/u/VladM)
#### Post date: [July 6, 2008, 7:49pm UTC](https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044/2 "2008-07-06T19:49:19Z")

</div>

Sorry, I was away a couple of days. Thanks for the answer, that did the trick with the code. But I still don’t get the part with the script files. Didn’t see anything related to them in the preferences panel. I always get stuck on simple things like this one, especially when I don’t even know what to google for to get the answer… :{ it’s so frustrating. I know it sounds moronic but could you give me a more elaborate answer in how to make my swf to recognise the code within the .as files? Just pretend i’m a robot. Thanks :block:

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [July 8, 2008, 5:46am UTC](https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044/3 "2008-07-08T05:46:06Z")

</div>

Using _Event_ as opposed to _MouseEvent_ does change the basic functionality. A MouseEvent is a kind of Event, so unless you require some specific functionality of MouseEvent, there is no functional difference between using one over the other.

---

<div class="post-metadata">

### Author: ![VladM](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@VladM](https://forum.kirupa.com/u/VladM)
#### Post date: [July 9, 2008, 8:05am UTC](https://forum.kirupa.com/t/using-as-files-simple-remove-button/265044/4 "2008-07-09T08:05:51Z")

</div>

Thank you all for your answers. I’ll start digging into that document class thing so I can get my swf’s working. Thanks for the link mattrock.
