A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: calling a public function in AS file

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    2

    calling a public function in AS file

    I have a Harbor_mc.AS file which adds several ship_mc's dynamically to its container on stage making sure I used a listener for ADD_TO_STAGE. From the Main Timeline the user inputs a name in a input textfield for his ship which calls a public function ShipBuy decalred in the Harbor_MC. This accepts the String argument. The only way I could get this function to work as public was placing it outside the harbor_mc function:

    Code:
    package {
    	import flash.display.*;
    	import flash.text.*;
    	import flash.events.*;
     	import Ship;
    
    	public class HarborFleet_MC extends Sprite {
             //variables go here
            public function HarborFleet_MC( ) {
    //all dynamically added mc's done here with their addedEventListeners
    //and functions 
    }
      public function ShipBuy(playerShipName:String):void {
    shipLabel_txt.text = playerShipName;
    ship_mc.removeEventListener(MouseEvent.CLICK, onClick); //not working!
    }
    
    }
    }
    from main timline:

    Code:
    MovieClip(root).harbor_mc.portFleet.onShipBuy(shipName); //this works
    It seems that I can access all variables declared above but cannot remove listeners from mc's. As a test I removed listeners inside the public function HarborFleet( ) brackets and it works but from the public function ShipBuy it gives me the grey screen of death.

    1. How do I make a publicly accessible function within the class Harbor_MC function?
    2. Or how to remove the listeners from mc's from a public function declared outside of the main function?

    I hope I am making this clear while tying to keep this brief on the concept.
    Basically I want the user to click on various mc's placed on the stage via external AS, view them, buy one of them, rename it and send the name back to Harbor_MC where the unselected mc's have their addEventListeners removed but still be on the stage.

    Thanks in advance for gotcha's I'm missing or a better solution all-together.

  2. #2
    Junior Member
    Join Date
    Aug 2006
    Posts
    13
    Just seeing your barebones code...

    I believe your issue is not removing the event listener but trying to target the ship_mc to call the removeEventListener for it.

    Usually, when I removeEventListener within a function, I have to target the correct clip first. i.e. this.getChildByName("correct ship_mc name").removeEventListener...
    Last edited by webbie5; 06-04-2008 at 10:32 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center