Flash AS3 - 如果我更改标签,舞台上的按钮将不会隐藏 - 错误或丢失某些内容?

发布于 2024-08-02 00:32:50 字数 669 浏览 1 评论 0原文

好吧 - 每次都会发生奇怪的问题 - 所以我想我一定是错过了一些非常明显的东西。

如果在 Flash CS3 中,我将一个 Button 组件拖到舞台上,并在文档类中,我使用visible = false隐藏该按钮; - 效果很好。 但是,如果我将该按钮的标签从默认的“标签”更改为任何内容,则该按钮不会变得不可见......

例如。 名为 hide_btn 的按钮,文档类 Foo:

package {   
    import flash.display.MovieClip;

    public class Foo extends MovieClip{
        public function Foo(){
            hide_btn.visible = false; // Works ONLY if I didn't change the button label!!
        }
    }   
}

当我运行影片时,该按钮(正确)不可见... 如果我将标签更改为“LabelX”,那么按钮仍然存在...

所以如果它是一个错误,肯定有人会注意到这一点,对吗? 那么 - 有人能解释一下发生了什么事吗?

干杯。

附言。 一丝踪迹(hide_btn.visible)说假,尽管它显然不是......

OK - weird problem which happens each time - and so I'm thinking I must just be missing something very obvious.

If in Flash CS3 I drag a Button component to the stage, and in the Document Class I hide that button with visible = false; - it works fine.
However, if I change the label of that Button from it's default 'Label' to anything else, the button does not go invisible...

eg. Button named hide_btn, Document Class Foo:

package {   
    import flash.display.MovieClip;

    public class Foo extends MovieClip{
        public function Foo(){
            hide_btn.visible = false; // Works ONLY if I didn't change the button label!!
        }
    }   
}

The Button is (correctly) invisible when I run the movie...
If I change the label to, say, 'LabelX' - then the Button is still there...

So surely someone would have noticed this before if it were a bug, right??
So - can someone explain what is going on?

Cheers.

PS. A trace of trace(hide_btn.visible) says false, even though it clearly isn't...

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

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

发布评论

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

评论(4

把回忆走一遍 2024-08-09 00:32:51

如果您等到初始加载后才隐藏按钮组件,则 .visible = false 将起作用。
例如,在构造函数中设置 myBtnComponent.visible = false 将不起作用,而是将其添加到构造函数的

public 函数 中
{
loaderInfo.addEventListener(Event.COMPLETE, init);
然后

void

私有函数 init(e:Event):
{
loaderInfo.removeEventListener(Event.COMPLETE, init);
myBtnComponent.visible = false

相信,当应用程序首次启动时,组件将从组件检查器加载其初始设置,因此通过侦听初始 loaderInfo 完成事件,您可以在组件实例化后更改组件的属性。

-戴夫-

If you wait to hide your button components until after the initial load .visible = false will work.
for example in the constructor setting myBtnComponent.visible = false will NOT work, instead add this into to the constructor

public function your constructor
{
loaderInfo.addEventListener(Event.COMPLETE, init);
}

then

private function init(e:Event):void
{
loaderInfo.removeEventListener(Event.COMPLETE, init);
myBtnComponent.visible = false
}

I believe that the components will load their initial settings from the compnent inspector when the application first launches, so by listening for the initial loaderInfo complete event, you can then change the properties of your components after they have instantied.

-Dave-

浮世清欢 2024-08-09 00:32:51

好吧,我不相信解决方案已经发布,尽管我认为建议的解决方案非常酷并且对于测试目的很有用。 我尝试使舞台无效,但使用新的 Flash 文件时问题仍然存在,除了给定的代码之外什么都没有......一旦我更改标签,我就无法隐藏按钮。 在更改标签之前,它可以工作。

我认为最好的解决方案可能是创建一个按钮对象或以某种方式导出按钮以供动作脚本使用,然后设置位置、可见性和标签属性。 今晚我要尝试一下,然后让你知道它是如何运作的。 我有一个巨大的项目,这个问题正在搁置......

Okay, I don't believe the solution has been posted, though I think the suggested solution are very cool and useful for test purposes. I tried invalidating the stage and the problem still persists with a new flash file with nothing but the code given... as soon as I change the label, I can't hide the button. Before changing the label, it works.

I think the best solution may be to create a button object or somehow export the button to be used by actionscript, and then set the position, visibility and label properties, afterward. I'm going to try this tonight and will let you know how it works. I have a huge project that this issue is holding up...

凉世弥音 2024-08-09 00:32:51

解决方案如下:

对于遇到此问题的任何此类按钮,右键单击它,转换为符号并选择影片剪辑(当然,除非您希望它是其他东西)。
将名称从 Symbol1 更改为更具描述性的名称(previous_btn 对我有用)。
在此对话框的“链接”部分中,选择“导出为 Actionscript”和“导出到第一帧”(如果这对您有用 - 第一帧通常是我的偏好)...单击“确定”。

再次右键单击该按钮,然后选择编辑,然后从属性按钮更改标签。 将大小更改为所需的比例(高和宽),然后单击场景(即场景 1)以退出编辑模式。 测试并享受,它现在工作可靠。 这比编写从影片剪辑创建按钮的代码更容易。

Here is the solution:

For any such button you are having this problem with, right click it, convert to symbol and select Movie Clip (unless you want it to be something else, fo course).
Change the name from Symbol1 to something more descriptive (previous_btn worked for me).
In the Linkage section of this dialog box, choose "Export for Actionscript" and "Export to First Frame" (if that works for you - first frame is usually my preference).... Click Okay.

Right click the button again, and choose edit, and change the label from the properties button. Change the size to your desired proportions (H and W), then click your Scene (i.e. Scene 1) to get out of edit mode. Test and enjoy, it works reliably now. This is easier than writing the code to create the button from a movie clip.

最佳男配角 2024-08-09 00:32:50

时髦的一个!

没想到:)

我也有类似的问题......但不完全是。 我试图访问影片剪辑后面一帧中的一些剪辑,就像在 as2 中一样,但除非播放头转到该帧,否则在 as3 中,剪辑将为空。

解决方法是强制舞台失效并访问 RENDER 事件中的对象(我认为这发生在所有内容在舞台上渲染之前,但在所有内容准备好/可访问之后)

我的猜测是因为您设置了标签在“参数”选项卡中,它在文档类构造函数之后进行评估,因此按钮组件失效中可能有一些东西告诉它是可见的。 完成所有操作后将其设置为不可见会更安全。

这是更新后的代码...著名的最后一句话:“它对我有用”:)

   package {   
    import flash.display.MovieClip;
    import flash.events.Event;
    public class Foo extends MovieClip{
        public function Foo(){
            //stage.invalidate() forces the stage to re-evaluate itself
            stage.invalidate();
            stage.addEventListener(Event.RENDER, stageRenderHandler);
        }
        //the RENDER events gets fired when invalidation is done
        //and everything is ready to be displayed/rendered
        private function stageRenderHandler(event:Event):void{
            hide_btn.visible = false; // Works
        }
    }   
}

Funky one!

Didn't expect that :)

I had sort of a similar issue...well not quite. I was trying to access some clips in a later frame of a movieclip, just like in as2, but unless the playhead goes to that frame, in as3, the clips are null.

The workaround is to force the stage to invalidate and access the objects in the RENDER event ( which I think happens right before all the stuff gets rendered on stage, but after all your stuff is ready/accessible )

My guess is since you set the label in the Parameters tab, that gets evaluated after the Document class constructor, so there might be something in the Button Component invalidation that tells it to be visible. It's safer to set it invisible after all that is done.

Here is the updated code...famous last words: 'it works for me' :)

   package {   
    import flash.display.MovieClip;
    import flash.events.Event;
    public class Foo extends MovieClip{
        public function Foo(){
            //stage.invalidate() forces the stage to re-evaluate itself
            stage.invalidate();
            stage.addEventListener(Event.RENDER, stageRenderHandler);
        }
        //the RENDER events gets fired when invalidation is done
        //and everything is ready to be displayed/rendered
        private function stageRenderHandler(event:Event):void{
            hide_btn.visible = false; // Works
        }
    }   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文