Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Flex (http://www.flasher.ru/forum/forumdisplay.php?f=84)
-   -   Ошибка при работе с XMLNotifier (http://www.flasher.ru/forum/showthread.php?t=142822)

Ivanaka 31.07.2010 19:55

Ошибка при работе с XMLNotifier
 
Здравствуйте,
Нужно отслеживать изменения XMLList, делаю так:
Код AS3:

import mx.utils.XMLNotifier;
public var updateWatch:XMLNotifier = XMLNotifier.getInstance();
 
......
 
updateWatch.watchXML(Global.usrdb, watch);//<--ошибка
private function watch():void{
                        trace("Изменено!")
                }

Выдает ошибку: 1067: Implicit coercion of a value of type Function to an unrelated type mx.utils:IXMLNotifiable

Не понимаю, вроде все сделал по хелпу.

wvxvw 31.07.2010 23:15

А зачем в хелп смотреть, если это на поверхности плавает?

Код AS3:

    public function watchXML(xml:Object, notifiable:IXMLNotifiable, uid:String = null):void
    {
        if ((xml is XMLList) && xml.length() > 1)
        {
            for each(var item:Object in xml)
            {
                watchXML(item, notifiable, uid);
            }
        }
        else
        {
            // An XMLList object behaves like XML when it contains one
            // XML object.  Casting to an XML object is necessary to
            // access the notification() function.
            var xmlItem:XML = XML(xml);
 
            // First make sure the xml node has a notification function.
            var watcherFunction:Object = xmlItem.notification();
 
            if (!(watcherFunction is Function))
            {
                watcherFunction = initializeXMLForNotification();
                xmlItem.setNotification(watcherFunction as Function);
                if (uid && watcherFunction["uid"] == null)
                    watcherFunction["uid"] = uid;
            }
 
            // Watch lists are maintained on the notification function.
            var xmlWatchers:Dictionary;
            if (watcherFunction["watched"] == undefined)
                watcherFunction["watched"] = xmlWatchers = new Dictionary(true);
            else
                xmlWatchers = watcherFunction["watched"];
 
            xmlWatchers[notifiable] = true;
        }
    }

И, ей богу, сделайте лучше сами, чем этим пользоваться.

Ivanaka 31.07.2010 23:52

Сам пока с трудом въезжаю, поэтому и спросил

Добавлено через 49 часов 50 минут
Решил проблему так: обернул XMLList в XMLListCollection, а у него уже есть стандартный слушатель изменений. Все работает.


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

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