Flash Action Script 3 旋转按钮

发布于 2024-12-13 12:48:26 字数 1336 浏览 0 评论 0原文

谁能告诉我这段代码有什么问题吗?我尝试旋转动作脚本 3 中的按钮,但不断收到错误消息:

ArgumentError:错误#2025:提供的 DisplayObject 必须是子对象 来电者的。在 flash.display::DisplayObjectContainer/removeChild() 在 tributor_app_fla::MainTimeline/NewChartOptionsReturn()[distributor_app_fla.MainTimeline::frame1:218] 在 tributor_app_fla::MainTimeline/ClickNewChartOptions()[distributor_app_fla.MainTimeline::frame1:101]

我已经用 Google 搜索了该错误,我读到的所有内容都告诉我删除子项,然后将其重新添加到框架中,但它继续在同一个地方。

代码:

//defined

var btnNewChartOptions:NewChartOptions = new NewChartOptions();

btnNewChartOptions.y = 279;

btnNewChartOptions.x = 439;

//created

function NewChartDown():String

{

btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);

    btnNewChartOptions.alpha = 0;

addChild(btnNewChartOptions);

var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);

return "NewChartSelected";

}

//actual code on button

function NewChartOptionsDown():String

{
rightGrayOut.alpha = 0;

addChild(rightGrayOut);

var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);

var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);



return "NewChartOptions";

}

任何帮助表示赞赏!

Could anyone tell me whats wrong with this code? I'm attempting to rotate a button in action script 3 and i keep getting the error:

ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller. at flash.display::DisplayObjectContainer/removeChild()
at
distributor_app_fla::MainTimeline/NewChartOptionsReturn()[distributor_app_fla.MainTimeline::frame1:218]
at
distributor_app_fla::MainTimeline/ClickNewChartOptions()[distributor_app_fla.MainTimeline::frame1:101]

I've already Googled the error and everything i read told me to remove the child then re-add it to the frame but it continues to break at the same spot.

code:

//defined

var btnNewChartOptions:NewChartOptions = new NewChartOptions();

btnNewChartOptions.y = 279;

btnNewChartOptions.x = 439;

//created

function NewChartDown():String

{

btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);

    btnNewChartOptions.alpha = 0;

addChild(btnNewChartOptions);

var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);

return "NewChartSelected";

}

//actual code on button

function NewChartOptionsDown():String

{
rightGrayOut.alpha = 0;

addChild(rightGrayOut);

var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);

var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);



return "NewChartOptions";

}

any help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺渁∝ 2024-12-20 12:48:26

不需要删除和重新添加对象,因为它要么存在并且可供方法使用,要么不可用,这意味着如果它可供方法删除,那么它也可用于寻址和操作。这听起来很像范围/可见性问题。

此代码位于时间轴上的第 1 帧上,这意味着它应该能够处理直接在舞台上或分配给函数运行时处于同一范围内的变量的任何内容。 (如果是 AS2,则在 _root 范围内,就像第 1 帧上的方法一样)

btnNewChartOptions 是否在另一个 DisplayObject 内,就像您用来容纳所有按钮或其他东西的精灵,而不是直接坐在舞台上?也许您可以描述您尝试解决的对象层次结构以及按钮如何附加到舞台(例如,在运行时实例化并附加或在关键帧中放置在舞台上)。

您能否提供在尝试添加和删除修复之前引发的错误?

There will be no need to remove and re-add the object because it is either present and available to the method or not, meaning if it were available to the method for removal then it would also be available for addressing and manipulation. This sounds a whole lot like a scope/visibility issue.

This code is on frame 1 on the timeline, which means that it should be able to address anything that's directly on the stage or assigned to a variable that is in the same scope at the time the function is run. (In the _root scope if this was AS2, like the methods on frame 1)

Is btnNewChartOptions inside another DisplayObject, like a sprite you use to hold all your buttons or something, as opposed to sitting directly on the stage? Maybe you can describe the object heirarchy you are trying to address as well as how the button gets attached to the stage (e.g. instantiated and attached at runtime or placed on the stage in a keyframe).

Can you provide the error that was being thrown before the add and remove fix was attempted?

小猫一只 2024-12-20 12:48:26

如果在我看来,该对象尚未添加到显示列表中。

// replace the following lines
removeChild(btnNewChartOptions);
addChild(btnNewChartOptions);

// with 
if( !this.contains( btnNewChartOptions ) ){
  return "";
}

[编辑]
你的代码。

//var created
  var btnNewChartOptions:NewChartOptions = new NewChartOptions();
  btnNewChartOptions.y = 279;
  btnNewChartOptions.x = 439;
//button code clicked that creates button
  function NewChartDown():String {
    btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);
    btnNewChartOptions.alpha = 0;
    addChild(btnNewChartOptions);
    var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);
    return "NewChartSelected";
  }




//function for button
  function NewChartOptionsDown():String {
    rightGrayOut.alpha = 0;
    addChild(rightGrayOut);
    var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);
    var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);
    return "NewChartOptions";
  }

在您提供的代码中,您仅在 NewChartDown 函数中执行 addChild(btnNewChartOptions); 操作。

这告诉我,在首先调用 NewChartDown 之前,无法调用 NewChartOptionsDown 。因为 btnNewChartOptions 从未被添加过。

您可以做的是将 addChild(btnNewChartOptions); 移到函数之外。

//var created
  var btnNewChartOptions:NewChartOptions = new NewChartOptions();
  btnNewChartOptions.y = 279;
  btnNewChartOptions.x = 439;
  addChild(btnNewChartOptions);

If looks like to me the object has not been added yet to the display list.

// replace the following lines
removeChild(btnNewChartOptions);
addChild(btnNewChartOptions);

// with 
if( !this.contains( btnNewChartOptions ) ){
  return "";
}

[EDIT]
Your code.

//var created
  var btnNewChartOptions:NewChartOptions = new NewChartOptions();
  btnNewChartOptions.y = 279;
  btnNewChartOptions.x = 439;
//button code clicked that creates button
  function NewChartDown():String {
    btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);
    btnNewChartOptions.alpha = 0;
    addChild(btnNewChartOptions);
    var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);
    return "NewChartSelected";
  }




//function for button
  function NewChartOptionsDown():String {
    rightGrayOut.alpha = 0;
    addChild(rightGrayOut);
    var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);
    var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);
    return "NewChartOptions";
  }

In your code you provided you are only doing addChild(btnNewChartOptions); in the NewChartDown function.

So that tells me that NewChartOptionsDown can not be called until NewChartDown has been called first. Because the btnNewChartOptions has never been added.

What you can do is move addChild(btnNewChartOptions); outside of the function.

//var created
  var btnNewChartOptions:NewChartOptions = new NewChartOptions();
  btnNewChartOptions.y = 279;
  btnNewChartOptions.x = 439;
  addChild(btnNewChartOptions);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文