Friday, March 26, 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