里面按钮实例名称问题实例、按钮、里面、名称

由网友(太多的包容)分享简介:我创建在Flash按钮,里面我有一个文本字段和影片剪辑中,都与设置实例名称。它们涵盖了按钮的所有4帧,没有关键帧。I've created a button in Flash, and inside that I have a TextField and a MovieClip, both with instance...

我创建在Flash按钮,里面我有一个文本字段和影片剪辑中,都与设置实例名称。它们涵盖了按钮的所有4帧,没有关键帧。

I've created a button in Flash, and inside that I have a TextField and a MovieClip, both with instance names set. They cover all 4 frames of the button, with no keyframes.

我发现使用实例名称我设置我无法访问的对象,所以我用这块code,看看发生了什么:

I found I couldn't access the objects using the instance names I'd set, so I used this piece of code to see what's going on:

var obj:DisplayObject = this.m_graphics.btnChange.upState;
for ( var i:int = 0; i < obj.numChildren; i++ )
{
    trace( "We have an object at " + i + " - " + obj.getChildAt( i ) + ": " + obj.getChildAt( i ).name );
    var t:TextField = obj.getChildAt( i ) as TextField;
    if ( t == null )
        continue;

    trace( "  The textfield has text '" + t.text + "' );
}

我得到这样的输出:

I get this as output:

We have an object at 0 - [object Shape]: instance195
We have an object at 1 - [object TextField]: instance199
  The textfield has text 'Change'
We have an object at 2 - [object MovieClip]: instance203

所以,他们文本字段和影片剪辑都在那里,他们只是有自己的实例名称重置为通用实例###。

So they TextField and MovieClip are there, they've just had their instance names reset to the generic "instance###".

任何人都知道是什么问题?如果我做了按钮的MovieClip,它工作正常(虽然我必须控制自己的帧)。

Anyone know what the problem is? If I make the button a MovieClip, it works fine (though I have to control the frames myself).

我知道不同的方法,我可以用它来解决这个问题,但是这意味着改变了很多东西,我想知道为什么的SimpleButton的忽略FLASH中的实例名称

I'm aware of the different methods I could use to work around this, but that means changing a lot of things, and I'd like to know why SimpleButton's ignore the instance names set in Flash

修改

寻找到它远一点,看来即使是在闪光灯IDE中的按钮没有关键帧,Flash会创建每个项目(通过北部跟踪的4个实例例如会给我一个文本字段实例名称INSTANCE2,而在唐斯泰特,实例名称是instance4)。如果我改变文本的一种状态,它不能反映其他人。

Looking into it a bit further, it seems that even though there's no keyframes in the button in the Flash IDE, Flash creates 4 instances of each item (tracing through the upState for example will give me a TextField with the instance name "instance2", while in the downState, the instance name is "instance4"). If I change the text in one state, it doesn't reflect in the others.

我在想,在Flash创建的对象,它不是在复制所有属性正确(即实例名)

I'm thinking that when Flash creates the objects, it's not copying over all the properties properly (namely the instance name)

修改

我同意,巴蒂尔的回答是一个解决办法 - 我会说我自己,我知道不同的方法来解决这个问题 - 但它忽略了这个问题,它并没有解决这个问题(这是唯一的原因,我没有接受它)。我来到SO摆在首位,看看是否有人也许知道为什么发生在首位(TBH,这似乎是在SDK中的错误)。

I agree that Shane's answer is a workaround - I'd said it myself that I know of the different methods to get around the problem - but it ignores the problem, it doesn't solve it (it's the only reason why I haven't accepted it). I came to SO in the first place to see if someone perhaps knows why it's happening in the first place (tbh, it seems like a bug in the SDK).

我也明白的说法背后的原因:你不应该访问的孩子的SimpleButton;如果你想要更多的控制,使用雪碧或MovieClip,但我不同​​意它。闪存IDE允许您创建里面他们命名实例按钮和SimpleButton的文档,您可以访问不同的状态,所以对我来说,这是公认的行为。如果SimpleButton的只能用于非常基本的,不可更改的静态按钮(想本地化为好),那么它的pretty的无用。您可以使用雪碧和MovieClip的,但你必须自己控制不同的状态,它得到尴尬。我有我自己的按钮类来处理的样板,但我不应该重写基本SDK的功能,这就是为什么对我来说这是一个错误。

I also understand the reasoning behind the argument "you shouldn't access children in SimpleButton; if you want more control, use Sprite or MovieClip", but I don't agree with it. The Flash IDE lets you create buttons with named instances inside them, and the SimpleButton docs give you access to the different states, so for me, this is accepted behaviour. If SimpleButton can only be used for very basic, non-changeable static buttons (think localisation as well), then it's pretty useless. You can use Sprite and MovieClip, but then you have to control the different states yourself, which gets awkward. I have my own Button class to handle the boilerplate, but I shouldn't have to rewrite basic SDK functionality, which is why for me it's a bug.

我会继续赏金打开的时候它的存在。如果我别的什么也没得到,那我就把它给巴蒂尔。

I'll keep the bounty open for the time it's there. If I get nothing else, then I'll give it to Shane.

推荐答案

这是因为flash.display.SimpleButton类不会从的DisplayObjectContainer 继承,并且状态容器也并不DisplayObjectContainers:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/SimpleButton.html

This is because the flash.display.SimpleButton class does not inherit from DisplayObjectContainer, and the state containers are also not DisplayObjectContainers: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/SimpleButton.html

基本上,简单的按钮都是由他们的定义简单。如果你在内部对象要更复杂的控制,你将不得不使用一个Sprite或MovieClip具有buttonMode设置为true。

Basically, simple buttons are by their definition simple. If you want more complex control over the inner objects you will have to use a Sprite or MovieClip with buttonMode set to true.

阅读全文

相关推荐

最新文章