# Fairly basic AS and dynamic image loading

**URL:** <https://forum.kirupa.com/t/fairly-basic-as-and-dynamic-image-loading/302389>\
**Category:** flash\
**Created:** [December 29, 2009, 12:09pm UTC](https://forum.kirupa.com/t/fairly-basic-as-and-dynamic-image-loading/302389 "2009-12-29T12:09:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rowan\_E](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Rowan\_E](https://forum.kirupa.com/u/Rowan_E)\
**Post date:** [December 29, 2009, 12:09pm UTC](https://forum.kirupa.com/t/fairly-basic-as-and-dynamic-image-loading/302389/1 "2009-12-29T12:09:41Z")

</div>

**Warning! If this AS makes you cry, I take no responsibility!**

Right, so I was told that the best place to put any code is in an external .as document. Problem 1: Can someone give me a template on how this should look? Any example I can find has some guy wanting to show off their amazing code skills with a massive chunk of unrelated code. My current ‘setup’ is:

package {

```
imports

public class extends mc or sprite{

    Public Variables

    Constructor function

    Other functions
}

```

}

This then means I must call the other functions from inside the .fla by directing them to root. Am I missing a trick here?

Problem 2: I want to load a movieclip based on a dynamic number, so when the number is 2, image 2 is loaded. To do this I’ve created a ‘constructor’ variable that combines the ‘prename’ of the image (since you can’t call a movieclip/image ‘2’) with the number. I then use that function in my addchild command. Seems to work, but again, is this smart or not?

Problem 3: Error #1007… Instantiation blah blah…

Problem code:  
function FillContainer1 (e:MouseEvent = null):void {  
//trace (PicCont1Child);  
this.addChild (new [PicCont1Child]);  
}

So I did some more reading and it seems the most common cause is messing up your classes and variables. I’m not all that hot-shot with OOP, but the class exists, exported from the library movieclip, and the variable traces fine. The idea is that I can call this function from inside a nested movie clip at a certain time. Sure, I could write all the code inside the movieclips, but that’s ugly, messy, and likely to go wrong. This counts as an ‘other function’ in the template I put up earlier, not a clue if that’s right or not, but it seemed logical.

Thanks in advance.
