Using .as files, simple remove button !?

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.


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.

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:

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.

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.