Attaching ActionScript to MovieClips in the Library

Hello everyone! Here is a question for ya.

In my library I have a bunch of movieclips that are dynamically going to be placed on my stage. Is there a simple method of attaching ActionScript to these movieclips so that when they are used on the stage, they have the script applied to them already?

Thanks in advance!

there are 2 basic ways to do this.

  1. write the script in those movieclips so when they’re created, the script is created right there with them (as the script is a part of the movie attached) ready to work as needed, or

  2. attach the clip and in referencing it, assign to it the functions needed to operate for whatever events are needed. For example, if you want an attached clip to move left ever frame, you would attach it and assign that attached clip to have an onEnterFrame function that would make it move left (every frame). To make it easier you can have these functions saved under other names prior to attaching the clips, and then just assign them after you do the actual attach. ex:

function moveLeft(){
    this._x -= 2;
this.attachMovie("movie_symbol_id", "bob", 1);
bob.onEnterFrame = moveLeft;

easy as that.