Форум 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)
-   -   Передача Button-объекта параметром функции (http://www.flasher.ru/forum/showthread.php?t=103689)

4oFF 10.11.2007 08:37

Передача Button-объекта параметром функции
 
Доброго времени суток!
Немного странная трабла:
Код:

function strReplace (strString:String, strFind:String, strReplace:String):String {
        var i:Number;
        var strRez:String = "";
        i = 0;
        while (i != strString.length) {
                if (strString.substr (i, strFind.length) == strFind) {
                        strRez += strReplace;
                        i += strReplace.length - 1;
                } else {
                        strRez += strString.substr (i, strFind.length);
                }
                i += strFind.length;
        }
        return strRez;
}
function load_country_info (country:String, city:String, Btn:Button) {
        var oxml = new XML ();
        //
        ioTxt.text = "";
        oxml.ignoreWhite = true;
        oxml.onLoad = function (success:Boolean) {
                if (success) {
                        var tx:String = "";
                        var item = Object ();
                        var i:Number = 0;
                        var imgContainer:MovieClip = _root.createEmptyMovieClip ("imgContainer", _root.getNextHighestDepth ());
                        var mclImg:MovieClipLoader = new MovieClipLoader ();
                        // а вот и трабла присвоение координат выполняется, по мувик не передвигается по этим координатам.
                        // но если выставитьстатичными цифрами эти координты, то всё ок
                        // trace() левой и правой части равенства показывает одинаковые координаты
                        // ВНИМАНИЕ ВОПРОС - почему не выполняется присваивание через Btn объект? может из-за его ссылочной сущности, но тогда как его обскакать?[/i][/color]
                        imgContainer._x = Btn._x;
                        imgContainer._y = Btn._y;
                        while (i != this.firstChild.childNodes.length) {
                                item = this.firstChild.childNodes[i];
                                if (item.nodeName.toUpperCase () == country.toUpperCase ()) {
                                        strRepl.replace (",", "\n");
                                        tx += "Population: " + item.attributes["population"] + "\n";
                                        tx += "Capital: " + item.attributes["capital"] + "\n";
                                        tx += "Money: " + item.attributes["money"] + "\n";
                                        //tx+="USD Exchange rate: "+item.attributes["usdexchrate"]+"\n";
                                        tx += "Timezones: \n\t" + strReplace (item.attributes["timezones"], ",", "\n\t");
                                        strReplRez = null;
                                        strRepl = null;
                                        if (city != "") {
                                                var strImgDir:String = item.firstChild.attributes["dir"];
                                                var strImgName:String = "";
                                                var j:Number = 0;
                                                while (j != item.firstChild.childNodes.length) {
                                                        if (item.firstChild.childNodes[j].attributes["name"].toUpperCase () == city.toUpperCase ()) {
                                                                strImgName = item.firstChild.childNodes[j].attributes["img"];
                                                                j = item.firstChild.childNodes.length - 1;
                                                        }
                                                        j++;
                                                }
                                                if (strImgName != "") {
                                                        mclImg.loadClip (strImgDir + "/" + strImgName, imgContainer);
                                                } else {
                                                        imgContainer.unloadMovie ();
                                                }
                                        } else {
                                                imgContainer.unloadMovie ();
                                        }
                                        i = this.firstChild.childNodes.length - 1;
                                }
                                i++;
                        }
                        ioTxt.text += tx;
                        item = null;
                        i = null;
                        j = null;
                        //imgContainer=null;
                        //mclImg=null;
                        //Btn=null;
                } else {
                        ioTxt.text = "XML FILE NOT LOADED - ERROR.\nPlease contact with WEB-ADMINISTRATORS\n emails here";
                }
        };
        oxml.load ('./countries_caspian_info.xml');
        oxml = null;
}
/* COUNTRIES */
CASPIAN_MAP.onRollOver = function () {
        load_country_info ("", "", null);
};
KZ_button.onRollOver = function () {
        load_country_info ("KZ", "", null);
};
TU_button.onRollOver = function () {
        load_country_info ("TU", "", null);
};
AZ_button.onRollOver = function () {
        load_country_info ("AZ", "", null);
};
/* CITIES */
Atyrau_button.onRollOver = function () {
        load_country_info ("KZ", "Atyrau", this);
};
Baku_button.onRollOver = function () {
        load_country_info ("AZ", "Baku", this);
};


iNils 10.11.2007 08:54

Для оформления своего кода, надо использовать теги [code][/code].

4oFF 10.11.2007 09:07

Да - сорри запарился. Зашёл чтобы подправить, а ужжо поздно. Спасиб.

iNils 10.11.2007 09:08

Вы везде в качестве But передаетет null, так откуда же координатам браться?

4oFF 10.11.2007 12:37

кнопка посылает свой объект
Код:

Atyrau_button.onRollOver = function () {
        load_country_info ("KZ", "Atyrau", this);
};

дело в том что чисто присвоения не происходит
могу исходник со всеми сопутсвующими фалами скинуть на мыло.

этот мув предназначен для отображения информации о стране(при наведении на территорию страны) либо высвечивает фото офиса (при наведении на город страны, в котором есть отделение - других городов просто не обозначено на карте мува). Следовательно null передается при наведении на страну, а this когда на город. почему так - потомучто данные беруться с одного xmlника и наведение обрабатывается одной и той же функции.

Работаю в CS3

etc 11.11.2007 12:23

4oFF, если надо что-то добавить, нужно редактировать пост, а не клепать кучу постов подряд.

4oFF 14.11.2007 16:33

ok. no krome etix preduprezhdeniy idei est'? - ved' trabla realnaya...

Наконец-то!!! Ответ был передомной и настолько прост:

объект создается так:
Код:

var imgContainer:MovieClip = _root.createEmptyMovieClip ("imgContainer", _root.getNextHighestDepth ());
, следовательно и присвоение необходимо организовывать
Код:

//не так
imgContainer._x=Btn._x;
//а вот так
_root.imgContainer._x=_Btn._x;



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

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