开发者

How can i control a button's actions that is inside a movie clip on AS3? (flash)

Helo guys, i have a button (name: closeinfo) inside开发者_StackOverflow社区 a moviclip (name: infopanel), im using this code to put actions to that button:

infopanel.closeinfo.addEventListener(
    MouseEvent.MOUSE_UP,
    function(evt:MouseEvent):void {
        trace("Im hit!!!");
  }
);

The code is in the main timeline, but it does not work, what im doing wrong? Thanks!

Error log:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at main_fla::MainTimeline/frame2()
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()


did you give your button instance, which is located inside "infopanel" movie clip the instance name "closeinfo"? it appears as if you forgot to do so.

also, your naming convention seems adverse to what's common: naming classes and variables is usually done in camel case, but classes start with capital letter while instances/variables do not (IE: camelCaseVar, CamelCaseClass). not following the convention wouldn't cause any errors, though.

one last nit-pick: function closures can make your code very difficult to manage. i suggest you avoid them, especially when adding event listeners that you might want to eventually remove.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜