Monday, March 22, 2010

Strange problem with...

I'm having problems working with an AS class that extends Dictionary. Here's a small code snippet that represents my problem:

package
{
聽聽聽 import flash.utils.Dictionary;


聽聽聽 public class DI extends Dictionary
聽聽聽 {
聽聽聽聽聽聽聽 public function DI(weakKeys:Boolean=false)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 super(weakKeys);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 public function setStuff():void
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 var d:Dictionary = new Dictionary();
聽聽聽聽聽聽聽聽聽聽聽 var key:String = ''CreationClassName'';
聽聽聽聽聽聽聽聽聽聽聽 var val:String = ''D13BCOR1'';
聽聽聽聽聽聽聽聽聽聽聽 d[key] = val;
聽聽聽聽聽聽聽聽聽聽聽 this[key] = val;
聽聽聽聽聽聽聽聽聽聽聽 trace(''key/val='' + val);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽
聽聽聽 }
}

Note that the line

d[key] = val;

works just fine.聽 However, the next line

this[key] = val;

gives me a runtime error:

ReferenceError: Error #1056: Cannot create property CreationClassName on DI.
聽聽聽 at DI/setStuff()[C:\jberry\workspaces\rnx\ActionScriptTest\DI.as:18]
聽聽聽 at ActionScriptTest()[C:\jberry\workspaces\rnx\ActionScriptTest\ActionScriptTest.a s:9]

Is there a different syntax than what I am using for setting a key/value combo for a class that extends Dictionary?

FYI, the code that calls the above looks like this:

聽聽聽聽聽聽聽 public function ActionScriptTest()
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 var di:DI = new DI();
聽聽聽聽聽聽聽聽聽聽聽 di.setStuff();
聽聽聽聽聽聽聽 }

Thanks in advance for any hints/suggestions.

Joe

Strange problem with...

Try public dynamic class DI.

Make sure Dictionary isn't ''final''

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

Strange problem with...

Thanks for the advice. That fixed the problem.聽 I need to do more homework to understand dynamic classes.

Joe

  • get ride of
  • No comments:

    Post a Comment