# addFrameScript()

**URL:** <https://forum.kirupa.com/t/addframescript/232807>\
**Category:** flash\
**Created:** [July 18, 2007, 12:03am UTC](https://forum.kirupa.com/t/addframescript/232807 "2007-07-18T00:03:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![efnx](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/efnx/32/3696_2.png) [@efnx](https://forum.kirupa.com/u/efnx)\
**Post date:** [July 18, 2007, 12:03am UTC](https://forum.kirupa.com/t/addframescript/232807/1 "2007-07-18T00:03:14Z")

</div>

I’d like to stay as far away from putting code in the timeline and manually putting objects on the stage as possible, so I’m trying to dynamically create a MovieClip and draw things on certain frames. I came across MovieClip.addFrameScript() which seems awesome except I haven’t been able to get it to work yet. Here is some simple code, I know there’s a step I’m missing…

```auto

var mc:MovieClip = new MovieClip();
    mc.addFrameScript(0, onFrame1);
    addChild(mc);
    
function onFrame1():void
{
    trace("Main::onFrame1(): " + mc.currentFrame);
}
    
addEventListener(Event.ENTER_FRAME, test);
    
function test(event:Event):void
{
    trace(mc.currentFrame);
}

mc.gotoAndStop(2);

```

This seems like it would work, but the only output I get is from the “test” function. Any help?
