Actionscript 3 dataProvider如何指向特定对象(不是通过索引)

Actionscript 3 dataProvider如何指向特定对象(不是通过索引),actionscript-3,indexing,dataprovider,Actionscript 3,Indexing,Dataprovider,如何使用对象数组中已存在的指定id在DataProvider中指向对象。 与例如类似,DataProvider包含一个对象,该对象具有一些属性:模型的路径/地址('testHouse/testHouseMD2.md2')和它的ID(“20”) 我可以使用getItemAt(index(“20”).address方法访问吗?或者它只能用于按索引获取对象,比如这个对象有ID(“20”),但它的索引可能指向“5”,所以当我在getItemAt中放入“20”时,我得到的对象是完全错误的 或者需要创建一个

如何使用对象数组中已存在的指定id在DataProvider中指向对象。 与例如类似,DataProvider包含一个对象,该对象具有一些属性:模型的路径/地址('testHouse/testHouseMD2.md2')和它的ID(“20”)

我可以使用
getItemAt(index(“20”).address
方法访问吗?或者它只能用于按索引获取对象,比如这个对象有ID(“20”),但它的索引可能指向“5”,所以当我在getItemAt中放入“20”时,我得到的对象是完全错误的

或者需要创建一个自己的方法来访问对象属性(ID),作为地址的
指针(索引)

如果是这样,请帮助我了解可以使用哪些构造函数-请!!

您应该重新填充对对象的访问:

const _map:Dictionary = new Dictionary();
const _collection:IList = new ArrayCollection();

function add(object:Object = null):Object {
  if (!object) return null;
  _map[object.id] = object;
  _collection.addItem(object);
  return object;
}

function getById(id:String):Object {
  if (!id) return null;
  return  object[id];
}

function getAt(index:uint):Object {
  if (index < 0) return null;
  return _collection.getItemAt(index);
}
这将提供一个id访问。

无论如何,我修复了这个问题 文章目录[prevIndex]。加载(标记@值)

我不需要使用数据提供者等,damnn im Noobb。
无论如何,thx需要帮助

thx需要回复,我正在使用markers.xml
Hey Florian,我使用getById时出错,它告诉我没有属性-对象(未声明),我不知道如何在DataProvider中使用它,比如更改DataProvider.getById(“20”)如果是,我如何指向需要在这些数组中引起的对象(DataProvider)是否有多个对象,如地址、名称、id和其他?仍然无法获取=((您使用的是Flex还是Flash?我正在使用它,我想我找到了一种可能的方法来解决这个问题,但我不知道怎么做,重点是从.xml标记中解析/排序指定的项,item=“id”,并将其值赋值=检索对象的索引,例如,当分拣机到达对象(A)时。项(id)将其分配给对象(A)。索引(项(id)),但我不知道如何在代码中执行此操作?您能帮我解决问题吗?您可能想查看我最后的更改。
package io.floriansalihovic.collections {

  import flash.events.Event;
  import flash.events.IEventDispatcher;
  import flash.utils.Dictionary;

  import mx.collections.ArrayCollection;
  import mx.collections.IList;

  [Event(name="collectionChange", type="mx.events.CollectionEvent")]

  public class Collection implements IEventDispatcher, IList {

    /** Internal collection. */
    private var _collection:ArrayCollection;

    /** Dictionary for fast id lookup. */
    private var _dictionary:Dictionary;

    /** @inheritDoc */
    public function get length():int {
      return this._collection.length;
    }

    /**
     * The constructor.
     *
     * @param collection The default collection.
     */
    public function Collection(collection:ArrayCollection = null) {
      this._collection = collection || new ArrayCollection();
      this._dictionary = new Dictionary();
    }

    /** @inheritDoc */
    public function addEventListener(type:String,
                                     listener:Function,
                                     useCapture:Boolean = false,
                                     priority:int = 0,
                                     useWeakReference:Boolean = false):void {
      this._collection.addEventListener(type, listener, useCapture, priority, useWeakReference);
    }

    /** @inheritDoc */
    public function dispatchEvent(event:Event):Boolean {
      return this._collection.dispatchEvent(event);
    }

    /** @inheritDoc */
    public function removeEventListener(type:String,
                                        listener:Function,
                                        useCapture:Boolean = false):void {
      this._collection.removeEventListener(type, listener, useCapture);
    }

    /** @inheritDoc */
    public function hasEventListener(type:String):Boolean {
      return this._collection.hasEventListener(type);
    }

    /** @inheritDoc */
    public function willTrigger(type:String):Boolean {
      return this._collection.willTrigger(type);
    }

    /** @inheritDoc */
    public function addItem(item:Object):void {
      this._dictionary[item.id] = item;
      this._collection.addItem(item);
    }

    /** @inheritDoc */
    public function addItemAt(item:Object,
                              index:int):void {
      this._dictionary[item.id] = item;
      this._collection.addItemAt(item, index)
    }

    /** @inheritDoc */
    public function getItemAt(index:int,
                              prefetch:int = 0):Object {
      return this._collection.getItemAt(index, prefetch);
    }

    /**
     * Returns the object associated with the given id.
     * @param id The id of the object.
     * @return The object associated with the given id, null else.
     */
    public function getItemById(id:String):Object {
      return _dictionary[id];
    }

    /** @inheritDoc */
    public function getItemIndex(item:Object):int {
      return this._collection.getItemIndex(item);
    }

    /** @inheritDoc */
    public function itemUpdated(item:Object,
                                property:Object = null,
                                oldValue:Object = null,
                                newValue:Object = null):void {
      this._collection.itemUpdated(item, property, oldValue, newValue);
    }

    /** @inheritDoc */
    public function removeAll():void {
      this._collection.removeAll();
      this._dictionary = new Dictionary();
    }

    /** @inheritDoc */
    public function removeItemAt(index:int):Object {
      const object:Object = this._collection.removeItemAt(index);
      delete _dictionary[object.id];
      return object;
    }

    /** @inheritDoc */
    public function setItemAt(item:Object,
                              index:int):Object {
      this._dictionary[item.id] = item;
      this._collection.setItemAt(item, index);
    }

    /** @inheritDoc */
    public function toArray():Array {
      this._collection.toArray();
    }
  }
}