Announcement Announcement Module
Collapse
No announcement yet.
How to get id by Object instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get id by Object instance

    <object id="objectId" class="com.xxx.xxx.AbcObject" />

    Now I have got the instance of the object abcObject.

    how can I get the id-"objectId" of it in xml config file?

    Thanks

  • #2
    var clazz:Class=Class(getDefinitionByName(getQualified ClassName(object)));
    var objectNames:Array=this._applicationContext.getObje ctNamesForType(clazz);
    for(var j:int=0;j<objectNames.length;j++) {
    var objectName:String = objectNames[j];
    if(object==this._applicationContext.getObject(obje ctName)){
    //do with objectName;
    }
    }

    Comment


    • #3
      why?

      Hey Nathan,

      please keep in mind that the code you've posted will only work on objects that have been marked as singletons. Non-singleton objects will yield a new instance everytime you call _applicationContext.getObject().

      If you want to keep track of those you will have to create your own mechanism that keeps track of what object belongs to which object id.

      I guess something like this could work:

      Code:
      var objectName:String = 'SomeObjectId';
      var objectIdRegistry:Dictionary = new Dictionary(true);
      var object:Object = _applicationContext.getObject(objectName);
      objectIdRegistry[object] = objectName;
      than somewhere else in your code if you want to know the object id that the object originated from:
      Code:
      var objectName:String = objectIdRegistry[object] as String;
      That way you can keep track of both singletons and prototyped objects.

      Hope that helps a little,

      cheers,

      Roland

      Comment


      • #4
        Thank you very much.

        Comment

        Working...
        X