as3 dynamic button name capturing problem

守給你的承諾、 提交于 2019-12-24 20:32:02

问题


i am using this code below to dynamically capture the name of the button pressed and then playing the related balloon movie clip animation.

stage.addEventListener(MouseEvent.CLICK, player); 

function player(evt:MouseEvent){
var nameofballoon = evt.target.name;
 nameofballoon =nameofballoon.substring(nameofballoon.length-1,nameofballoon.length);
var movie = "balloon"+nameofballoon;
 trace(movie);
movie.gotoAndPlay("burst");

  }

i'm getting this error even though the name of the clip capture by the event is correct

TypeError: Error #1006: value is not a function.
at Balloons2_fla::MainTimeline/player()

any thoughts ? what wrong with this code?


回答1:


Your variable movie is considered as a String.
You should try something like this :

var movie:MovieClip = this["balloon"+nameofballoon];
movie.gotoAndPlay("burst");

You may have to replace this by the name of the parent of your ballonX MovieClip.




回答2:


var movie = "balloon"+nameofballoon;
trace(movie);
movie.gotoAndPlay("burst");

movie is a string - there is no gotoAndPlay method in String class.

Use

var movie:MovieClip = this.getChildByName("balloon"+nameofballoon);
movie.gotoAndPlay("burst");


来源:https://stackoverflow.com/questions/2478985/as3-dynamic-button-name-capturing-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!