Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Непонятный баг getTextExtent (http://www.flasher.ru/forum/showthread.php?t=98553)

tracert 16.07.2007 16:04

Непонятный баг getTextExtent
 
При нажатии на кнопку добавляется текстовое поле, при установке фокуса на этом поле измеряются его размеры для последующего использования. При этом удаляется мувиклип который не как с этими функциями не связан.

Скопировал пример getTextExtent из хелпа один в один та же ерунда.

Код:

function newTextLayer() {
        mcTools.createTextField("mcNewLayer"+LayerCount, LayerCount, 100, 100, 200, 100);
       
        trace ("img " +_level0.img_mc) //возвращает ссылку на mc
        mcTools["mcNewLayer"+LayerCount].type = "dynamic";
        mcTools["mcNewLayer"+LayerCount].text = NewLayerText;
        txtInput.text = mcTools["mcNewLayer"+LayerCount].text;
        var textStr:String = mcTools["mcNewLayer"+LayerCount].text;
               
       
        mcTools["mcNewLayer"+LayerCount].onSetFocus = function() {
                                       
                                        var my_str:String = "Small string";
                                        // Create a TextFormat object,
                                        // and apply its properties.
                                        var my_fmt:TextFormat = new TextFormat();
                                        with (my_fmt) {
                                                font = "Arial";
                                                bold = true;
                                        }
                                       
                                        // Obtain metrics information for the text string
                                        // with the specified formatting.
                                        var metrics:Object = my_fmt.getTextExtent(my_str);
                                       
                                        // Create a text field just large enough to display the text.
                                        this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100, metrics.textFieldWidth,
                                        metrics.textFieldHeight);
                                        my_txt.border = true;
                                        my_txt.wordWrap = true;
                                        // Assign the same text string and TextFormat object to the my_txt object.
                                        my_txt.text = my_str;
                                        my_txt.setTextFormat(my_fmt);

                trace ("img " +_level0.img_mc) //возвращает undefined
               
               
        };
}


что делать? кто с таким сталкивался?

etc 16.07.2007 16:14

Вероятно, проблема в указанной глубине при создания текстового поля.

tracert 16.07.2007 16:53

Код:

var img_mc:MovieClip = _root.createEmptyMovieClip("img_mc", _root.getNextHighestDepth());  // depth 1048576
а у текста глубина 0, 1, 2 и т.д.

etc 16.07.2007 17:03

Если в проекте используются компоненты, то для работы надо использовать DepthManager вместо getNextHighestDepth().


Часовой пояс GMT +4, время: 21:47.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.