1

ComboBox コンポーネントをスプライトに追加すると、コンテナの高さが必要以上に大きくなります。

これが私が意味することです:

import fl.controls.ComboBox;
//add combo box inside a container sprite
var combo:ComboBox = new ComboBox();
var container:Sprite = new Sprite();
addChild(container);
container.addChild(combo);
//draw the outline of the container sprite
container.graphics.lineStyle(1,0x009900);
container.graphics.drawRect(0,0,container.width,container.height);
//I don't get this:
trace(combo.height);//outputs 22
trace(container.height);//outputs 101

注:ライブラリに ComboBox コンポーネントが必要になります。これにはFlash CS3を使用しています。

次のように、無効化/再描画すると:

combo.invalidate(InvalidationType.ALL,true);
combo.drawNow();

高さは 101 から 104 に変化します。

解決策はありますか?

更新: ComboBox サブクラスの configUI メソッドを上書きしましたが、測定値は常に正しいです。コンテナーの高さが 100 に変わるのはなぜですか?

4

6 に答える 6

3

これは、AdobeがFlashコンポーネントをばかげて移植したためです。FlashIDEA内のコンポーネントの2番目のフレームを見ると、初期サイズを返す一時的なアバターであ​​ることがわかります。

ここに画像の説明を入力してください

これを解決するには、アバターの子を繰り返し処理し、サイズを正規化する必要があります。

public static function normalizedComponent(component:Sprite):void {
    for (var i:int = 0; i < component.numChildren; i++) {
        component.getChildAt(i).height = component.height;
        component.getChildAt(i).width = component.width;
    }
}

利用方法:

var comboBox:ComboBox = new ComboBox();
normalizedComponent(comboBox);
normalizedComponent(comboBox.textField);
于 2012-11-13T14:56:13.273 に答える
1

I don't think this a ComboBox exclusive bug.

When I add a component Button to a Sprite container I also get different results when tracing the button and the container dimensions. Actually, I receive the same 100 x 100 results.

I would discard the drop down box possibility, since the Button component doesn't have one.

I think the workaround would be the same for the 2 components objects (ComboBox and Button), but I haven't found the solution just yet. Will update when I do.

UPDATE:

I was just able to get this working using validateNow(), and a few minutes later - I found the following link: http://forums.adobe.com/message/816912?tstart=0

Essentially, the link instructs us to put the validateNow() call inside an EnterFrame event, or inside a SetTimeout with proper timing.

于 2011-01-29T20:01:10.320 に答える
1

「開いている場合は、ドロップダウン ボックスを含む高さ」

うーん、リストがボタンの下のdisplayListに追加されると、実際に追加されたポップアップが表示されると思います。したがって、スプライトには実際にドロップダウン リストが含まれることはないため、高さはボタンの高さのままであると想定されます。

コンテナが無効化される前にコンテナの高さが間違っている可能性がある理由として考えられるのは、コンテナに含まれる子が原因である可能性があります。おそらく、コンボボックスのスキン (高さ 102px の movieClip である可能性があります) や、常に 102px の高さまたは奇妙な高さで始まるコンボボックスのサブコンポーネント (Button の TextField は、時々間違っていることが知られています)。

簡単な解決策は、creationComplete/added イベントまで待機し、最終的な高さを確認してから、境界線を描画することです。

于 2010-09-30T11:47:45.367 に答える
0

こんにちは、NumericStepper に関する同様の問題の解決策をどこかで見つけました。

解決策は次のとおりです。

var tInput:TextInput = numericStepper.getChildAt(2) as TextInput;
tInput.textField.height = 22; 

あなたの場合、次のことを試してください。

var tInput:TextInput = combo.getChildAt(1) as TextInput;
tInput.textField.height = 22; 
于 2010-11-11T06:26:21.337 に答える
0

だから - ComboBoxの表示された高さは実際の高さだと思います.id est、開いている場合はドロップダウンボックスのある高さ、そうでない場合はなしの高さです。ただし、アイテムはまだそこにありますが、 .visible がfalseに設定されているため、それが見えなくてもコンテナーが展開されます...したがって、私は次のように言います:

container.graphics.drawRect(0, 0, combo.width, combo.height);

それも普段のやり方…。

于 2010-09-06T15:21:13.410 に答える
0

このコードの前に手動でセットアップできますか:

container.width=100;

container.height=100;

container.graphics.drawRect(0,0,container.width,container.height);

于 2010-09-07T14:11:00.440 に答える