# Using methods from another SWF

**URL:** <https://forum.kirupa.com/t/using-methods-from-another-swf/290638>\
**Category:** flash\
**Created:** [June 17, 2009, 3:21pm UTC](https://forum.kirupa.com/t/using-methods-from-another-swf/290638 "2009-06-17T15:21:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alpha\_Remex](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Alpha\_Remex](https://forum.kirupa.com/u/Alpha_Remex)\
**Post date:** [June 17, 2009, 3:21pm UTC](https://forum.kirupa.com/t/using-methods-from-another-swf/290638/1 "2009-06-17T15:21:24Z")

</div>

Okay, so I am testing interaction between two swf’s on one web page so that I can understand how it all works before starting development.

I have two classes: the actual program (called AdminTool) and a navigation swf (called Navigation).

Here is my code for the actual tool:

```auto

package {
    
    import flash.display.MovieClip;
    import flash.display.Sprite;
    
    public class AdminTool extends MovieClip {
        
        public function AdminTool(){}
        
        public function createTest():void {
            var shape:Sprite = new Sprite();
            shape.graphics.beginFill(0x00,1);
            shape.graphics.drawRect(10,10,10,10);
            shape.graphics.endFill();
            
            this.addChild(shape);
        }
        
        public function editTest():void {
            var shape:Sprite = new Sprite();
            shape.graphics.beginFill(0x00,1);
            shape.graphics.drawCircle(10,10,10);
            shape.graphics.endFill();
            
            this.addChild(shape);
        }
        
        public function deleteTest():void {
            var shape:Sprite = new Sprite();
            shape.graphics.beginFill(0x00,1);
            shape.graphics.drawRoundRect(100,10,20,20,3,3);
            shape.graphics.endFill();
            
            this.addChild(shape);
        }
        
        public function reports():void {
            var shape:Sprite = new Sprite();
            shape.graphics.beginFill(0x00,1);
            shape.graphics.drawRoundRect(20,100,20,20,5,5);
            shape.graphics.endFill();
            
            this.addChild(shape);
        }
    }
}

```

Real simple… just want a visual cue here that the methods are being run since I can’t see traces on the web page.

Here is the code for the navigation piece:

```auto

package {
    
    import flash.display.Sprite;
    import flash.events.*;
    
    public class Navigation extends Sprite {
        
        private var adminTool:AdminTool = new AdminTool();
        private var createButton:Sprite = new Sprite();
        private var editButton:Sprite = new Sprite();
        private var deleteButton:Sprite = new Sprite();
        private var reportsButton:Sprite = new Sprite();
        
        public function Navigation() {
            createButton.graphics.beginFill(0x00FF,1);
            createButton.graphics.drawRect(0,0,50,10);
            createButton.graphics.endFill();
            
            editButton.graphics.beginFill(0x00FF,1);
            editButton.graphics.drawRect(60,0,50,10);
            editButton.graphics.endFill();
            
            deleteButton.graphics.beginFill(0x00FF,1);
            deleteButton.graphics.drawRect(120,0,50,10);
            deleteButton.graphics.endFill();
            
            reportsButton.graphics.beginFill(0x00FF,1);
            reportsButton.graphics.drawRect(180,0,50,10);
            reportsButton.graphics.endFill();
            
            this.addChild(createButton);
            this.addChild(editButton);
            this.addChild(deleteButton);
            this.addChild(reportsButton);
            
            createButton.name = "create";
            editButton.name = "edit";
            deleteButton.name = "delete";
            reportsButton.name = "reports";
            
            createButton.buttonMode = true;
            editButton.buttonMode = true;
            deleteButton.buttonMode = true;
            reportsButton.buttonMode = true;
            
            createButton.addEventListener(MouseEvent.CLICK, clickListener);
            editButton.addEventListener(MouseEvent.CLICK, clickListener);
            deleteButton.addEventListener(MouseEvent.CLICK, clickListener);
            reportsButton.addEventListener(MouseEvent.CLICK, clickListener);
        }
        
        private function clickListener(e:MouseEvent):void {
            switch(e.target.name) {
                case "create":
                    adminTool.createTest();
                    break;
                case "edit":
                    adminTool.editTest();
                    break;
                case "delete":
                    adminTool.deleteTest();
                    break;
                case "reports":
                    adminTool.reports();
                    break;
            }
        }
    }
}

```

so this is executing the method’s from the first swf based on the button pressed… or at least it is supposed to…

So when I load the page, both swf’s appear and it looks like the buttons are taking the click event, but nothing is happening on the AdminTool swf.

Two questions:

[LIST=1]  
[_]What am I doing wrong?  
[_]Is there a better way to test this sort of thing? (Where I can get trace messages, etc)  
[/LIST]
