gpt4 book ai didi

flash - AS3 词典问题

转载 作者:行者123 更新时间:2023-12-04 11:29:41 24 4
gpt4 key购买 nike

关于 Actionscript 3 中的 Dictionary 类的几个问题:

  • 检查未使用 key 的最佳方法是什么?我在做dictionary[key] == undefined马上。这是最快最干净的方式吗?
  • 我是否必须遍历和delete dictionary[key]或者我可以让字典超出范围吗?
  • 是否有更好的解决方案将消息监听器映射到广播类?我做这样的事情:
    addListener(function : Function, messageType : Type)
    {
    if(dictionary[messageType] == undefined)
    dictionary[messageType] = new Vector<Function>();

    dictionary[messageType].push(function);
    }

    broadcast(message : Message, messageType : Type)
    {
    if(dictionary[messageType] != undefined)
    {
    for each(var function : Function in dictionary[messageType])
    function(message);
    }
    }

  • 我现在才打出来,所以它可能不是 100% 准确。使用带有字典的路由系统的好主意?

    最佳答案

    1 -- 您有两个有效选项:与 undefined 比较或与 null 比较.区别是这样的:

  • undefined : 值根本不存在
  • null : 值存在,但包含空值

  • 因此,您可以选择适合您情况的内容。请参阅示例。
    import flash.utils.Dictionary;

    var test:Dictionary = new Dictionary();

    trace(test[1] == null); // true, because null is internally converted to undefined
    trace(test[1] === null); // false, because of strictly typed comparison
    trace(test[1] == undefined); // true
    trace(test[1] === undefined); // true

    2 -- 当我在字典中有引用时,我总是循环遍历字典来清理它们(不仅仅是像数字或字符串这样的简单类型)。嗯,应该没有必要,但是这样我可以帮助垃圾收集器一点点,这通常是一个好主意。

    3 ——这让我很困惑。为什么需要这样广播?它看起来很像我们几天前在 AS1-2 中的 AsBroadcaster 类,它非本地为我们提供了广播功能。 AS3 有一个本地事件调度系统,您可以升级它以满足您的需要(例如,如果您需要为每个事件类型维护一个监听器列表)。

    这些链接可能有用:
  • http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.6
  • Whats the appropriate form when dispatching events in AS3?
  • 关于flash - AS3 词典问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6514232/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com