框架标签&功能参数

时间:2012-02-29 00:46:09

标签: actionscript-3 flash actionscript

是否可以使用函数中的参数更改gotoAndStop('label')中的帧标签?

随着我学习越来越多的技术,我正在玩更新代码,目前代码是一个基本的点按按钮来选择对象的形状,按下按钮就会消失:

// Change the object into a circle.
circle_btn.addEventListener(MouseEvent.CLICK,function(){changeShape_fun(circle_btn,circle);});

// Change the object into a square.
square_btn.addEventListener(MouseEvent.CLICK,function(){changeShape_fun(square_btn,square);});

// Change the object into a star.
star_btn.addEventListener(MouseEvent.CLICK,function(){changeShape_fun(star_btn,star);});

function changeShape_fun(shape_btn,frame){
shape_btn.visible = false;
main_mc.gotoAndStop('frame');
}

但是,我似乎不知道如何通过功能参数更改帧标签,或者我想要做什么甚至可能。

另外需要注意的是,虽然我很想知道我正在尝试做什么的更有效方法,但我仍然想知道如何/如果你可以通过函数参数更改帧标签。

谢谢! :)

1 个答案:

答案 0 :(得分:0)

你非常接近,但是你试图去一个名为'frame'的框架,而不是 frame 变量中包含的字符串。试试这个:

// Change the object into a circle.
circle_btn.addEventListener(MouseEvent.CLICK,function(event:MouseEvent){changeShape_fun(circle_btn, 'circle');});

// Change the object into a square.
square_btn.addEventListener(MouseEvent.CLICK,function(event:MouseEvent){changeShape_fun(square_btn, 'square');});

// Change the object into a star.
star_btn.addEventListener(MouseEvent.CLICK,function(event:MouseEvent){changeShape_fun(star_btn, 'star');});

function changeShape_fun(shape_btn,frame){
    shape_btn.visible = false;
    main_mc.gotoAndStop(frame);
}

如果单击方框等,当您单击圆圈或“方形”时,将转到 main_mc 中称为“圆圈”的框架。