0

I currently have two movieclips one called mcInvFrame, and one called btnCloseInv (It is a movieclip, and I know the naming convention is wrong). btnCloseInv is located inside mcInvFrame. I have two files Inventory.as and my main document class. I can load the mcInvFrame just fine to the stage and everything works as expected. However when I try to access the btnCloseInv movieclip i get errors. Here is the code for Inventory.as I have commented out my most recent failed attempt

package{
import flash.display.MovieClip;
import flash.events.MouseEvent;


public class Inventory extends MovieClip
{
    public var inv:MovieClip = new mcInvFrame;

    public function Inventory()
    {
        addChild(inv);
        /*var invClose:MovieClip = inv.btnCloseInv;
        invClose.addEventListener(MouseEvent.CLICK, CloseInventory);
        function CloseInventory($e:MouseEvent):void
        {
            this.parent.removeChild(inv);
        }*/
    }
}

}

What I need to know is can/should i create a variable within inventory.as for the button that I can access from the main document? If so how?

P.S. I have been searching the forums and trying various solutions but I either didn't understand the implementation or they were not suitable for this situation. The most common error I receive is "Error #1009: Cannot access a property or method of a null object reference." Occasionally I will receive an error stating that an object has no properties.

  • Have you definitely put an instance name on btnCloseInv? If you have, I think your code should work. – net.uk.sweet Jul 01 '13 at 23:38
  • Well I've gotten a suitable work around but it isn't what I had hoped for. Within the Inventory.as I added an instance of the close button and positioned it where I wanted it, I was able to get the button to work. I would like to access the button within the mcInvFrame movieclip to work, but I can't seem to figure out how to create an instance of a movieclip inside another movieclip. – user2540655 Jul 02 '13 at 03:20

1 Answers1

0

you cant register event on stage.movieclip.movieclip2 , i have tried to do the same thing before, but it wont work, try to create btnCloseInv outside, then use this code

btnCloseInv.x = mcInvFrame.x + numberHere;
btnCloseInv.y = mcInvFrame.y + numberHere2;

if you doesn't want to use this code, AS3 - Button inside MovieClip triggers MC's event

EDIT: if you set mcInvFrame.buttonMode = true it will not work

Community
  • 1
  • 1
wuiyang
  • 409
  • 2
  • 5
  • 18