0

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?

Amarghosh
  • 58,710
  • 11
  • 92
  • 121
hitek
  • 372
  • 1
  • 17
  • 33

2 Answers2

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.

Zed-K
  • 991
  • 2
  • 8
  • 23
0
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");
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
  • I ran into a similar problem. Your solution helped me, but I did have to cast the movie specifically as movieclip. Like this: var movie:MovieClip = this.getChildByName("balloon"+nameofballoon) as MovieClip; – silvith Dec 11 '12 at 13:19