# Seems easy, but isn't for me. Passing a variable to a function

**URL:** https://forum.kirupa.com/t/seems-easy-but-isnt-for-me-passing-a-variable-to-a-function/307738
**Category:** Uncategorized
**Created:** [April 9, 2010, 9:26am UTC](https://forum.kirupa.com/t/seems-easy-but-isnt-for-me-passing-a-variable-to-a-function/307738 "2010-04-09T09:26:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dtrace](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dtrace](https://forum.kirupa.com/u/dtrace)
#### Post date: [April 9, 2010, 9:26am UTC](https://forum.kirupa.com/t/seems-easy-but-isnt-for-me-passing-a-variable-to-a-function/307738/1 "2010-04-09T09:26:39Z")

</div>

It seems that with as3, the error compiler is just waiting to get you.

I have a function that loads in an external swf. Which swf depends on which button they click. So, it could be pic1.swf, pic2.swf, pic3.swf, etc.

function loadMovie(){

my\_mc.addChild(my\_Loader);  
addChild(my\_mc);

var my\_url:URLRequest=new URLRequest(“pic” + myVariable + “.swf”);  
my\_Loader.load(my\_url);

my\_mc.x = 206;  
my\_mc.y = 100;

```
}

```

Here is the code for one of the buttons that triggers the loadMovie function.

myButton.addEventListener(MouseEvent.CLICK, onClicknav2);

function onClicknav2(event:MouseEvent):void {

var myVariable:Number = 1;  
loadMovie();

}

When i test, I get "error: access to undefined property myVariable. ’

What is going on ? What must I do to make this right?

Thanks.
