# Creating Variable for MC in External .FLA

**URL:** <https://forum.kirupa.com/t/creating-variable-for-mc-in-external-fla/261711>\
**Category:** flash\
**Created:** [May 30, 2008, 3:30am UTC](https://forum.kirupa.com/t/creating-variable-for-mc-in-external-fla/261711 "2008-05-30T03:30:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daimz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/daimz/32/2383_2.png) [@Daimz](https://forum.kirupa.com/u/Daimz)\
**Post date:** [May 30, 2008, 3:30am UTC](https://forum.kirupa.com/t/creating-variable-for-mc-in-external-fla/261711/1 "2008-05-30T03:30:38Z")

</div>

I have got a AS3 Dock Menu script from [http://www.reloc.org/2008/2/23/os-x-dock-in-as3-and-flex](http://www.reloc.org/2008/2/23/os-x-dock-in-as3-and-flex)

And I am trying to get it to Load content in to a Movie Clip when an icon is pressed but I am having some serious trouble doing it. I had it sugested to me that I try using cases so I did but then I needed to create a Variable in the .AS file(below) but I am totally lost.

Would some one tell me what I am doing wrong or what I could do to get it working.  
My movie Clip that I want to load images in to in the .Fla is called “ldr”.

original code:

```auto
package
{
    import flash.display.MovieClip;
    import org.reloc.dock.*;
    
    public class DocumentClass extends MovieClip
    {
        private var items = [
                    { icon: new finder(128, 128), id: 'finder' },
                    { icon: new safari(128, 128), id: 'safari' },
                    { icon: new mail(128, 128), id: 'mail' },
                    { icon: new itunes(128, 128), id: 'itunes' },
                    { icon: new ichat(128, 128), id: 'ichat' },
                    { icon: new search(128, 128), id: 'search' },
                    { icon: new help(128, 128), id: 'help' },
                    { icon: new trash(128, 128), id: 'trash' }
                    ];

        public function DocumentClass()
        {
            stage.scaleMode = 'noScale';

            var dock:Dock = new Dock('bottom', 128, 32, 128, 2, 0, 0, items);
            dock.x = stage.stageWidth / 2;
            dock.y = stage.stageHeight;
            addChild(dock);
            
            addEventListener(DockEvent.CLICK, onClick);
        }
        
        private function onClick(event:DockEvent):void
        {
            var icon:DockIcon = event.target as DockIcon;
            trace(icon.info.id)
        }
    }
}

```

My changes

```auto

package
{
    import flash.display.MovieClip;
    import org.reloc.dock.*;
    
    public class DocumentClass extends MovieClip
    {
        private var items = [
                    { icon: new finder(128, 128), id: 'finder' },
                    { icon: new safari(128, 128), id: 'safari' },
                    { icon: new mail(128, 128), id: 'mail' },
                    { icon: new itunes(128, 128), id: 'itunes' },
                    { icon: new ichat(128, 128), id: 'ichat' },
                    { icon: new search(128, 128), id: 'search' },
                    { icon: new help(128, 128), id: 'help' },
                    { icon: new trash(128, 128), id: 'trash' }
                    ];

        public function DocumentClass()
        {
            stage.scaleMode = 'noScale';

            var dock:Dock = new Dock('bottom', 128, 32, 128, 2, 0, 0, items);
            dock.x = stage.stageWidth / 2;
            dock.y = stage.stageHeight;
            addChild(dock);
            
            addEventListener(DockEvent.CLICK, onClick);
        }
        
        private function onClick(event:DockEvent):void
        {
            var icon:DockIcon = event.target as DockIcon;
            var ldr:MovieClip
            //trace(icon.info.id)
            switch(this.DockIcon) {
                case 'finder':
                this.ldr.source = "clip1.swf";
                Break;
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![sudhansurana](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@sudhansurana](https://forum.kirupa.com/u/sudhansurana)\
**Post date:** [May 30, 2008, 6:50am UTC](https://forum.kirupa.com/t/creating-variable-for-mc-in-external-fla/261711/2 "2008-05-30T06:50:55Z")

</div>

try this

> 

package  
{  
import flash.display.MovieClip;  
import flash.net.URLRequest;  
import org.reloc.dock.\*;  
import flash.display.Loader;

```
public class DocumentClass extends MovieClip
{
	private var ldr:Loader;
    private var items = [
    			{ icon: new finder(128, 128), id: 'finder' },
    			{ icon: new safari(128, 128), id: 'safari' },
    			{ icon: new mail(128, 128), id: 'mail' },
    			{ icon: new itunes(128, 128), id: 'itunes' },
    			{ icon: new ichat(128, 128), id: 'ichat' },
    			{ icon: new search(128, 128), id: 'search' },
    			{ icon: new help(128, 128), id: 'help' },
    			{ icon: new trash(128, 128), id: 'trash' }
    			];

	public function DocumentClass()
	{
	    stage.scaleMode = 'noScale';

		var dock:Dock = new Dock('bottom', 128, 32, 128, 2, 0, 0, items);
        dock.x = stage.stageWidth / 2;
        dock.y = stage.stageHeight;
		addChild(dock);
		ldr = new Loader();
		this.addChildAt(ldr,0);
		addEventListener(DockEvent.CLICK, onClick);
	}
	
	private function onClick(event:DockEvent):void
	{
	    var icon:DockIcon = event.target as DockIcon;
		switch(icon.info.id) {
            case 'finder':
			ldr.load(new URLRequest("clip1.swf"));
            break;
        }

	}
}

```

}

The mistake you had done  
1.

> switch(this.DockIcon) {

here you cant add switch element to a class Name insted use an instance or any function of the class  
which returns some value.

1. 

> Break;

it is break; not Break;

1. 

> var ldr:MovieClip  
> //trace(icon.info.id)  
> switch(this.DockIcon) {  
> case ‘finder’:  
> this.ldr.source = “clip1.swf”;  
> Break;  
> }

you have declared a movieClip name ldr which is not the child of this(here it is the root).  
Try loader class.to load the swf and add it to the root at your desired depth.

Cheers  
Sudhansu  
if you have any query plz visit  
[http://www.sudhansurana.wordpress.com/](http://www.sudhansurana.wordpress.com/)
