# Accessing Dictionary Object from Function

**URL:** <https://forum.kirupa.com/t/accessing-dictionary-object-from-function/274043>\
**Category:** flash\
**Created:** [October 24, 2008, 3:04am UTC](https://forum.kirupa.com/t/accessing-dictionary-object-from-function/274043 "2008-10-24T03:04:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [October 24, 2008, 3:04am UTC](https://forum.kirupa.com/t/accessing-dictionary-object-from-function/274043/1 "2008-10-24T03:04:20Z")

</div>

I’m trying to figure out how I can access the keys/data within a Dictionary object from within a public function. The basic code structure looks like this:

```auto

package {

    import flash.utils.Dictionary;

    public class TriviaGame extends MovieClip {

        public var dict:Dictionary = new Dictionary(true);

        public function askQuestion() {
            var answerField:TextField = createText(answer,answerFormat,answerSprite,0,0,450);
            dict[answerField] = answerField;
            trace("dict[answerField] = " + dict[answerField].text);// Gives correct data
        }
        public function clickAnswer(event:MouseEvent) {
            finishQuestion();
        }

        public function finishQuestion() {
            trace(dict[answerField]); //Error 1120: Access of undefined property answerField.
        }

    }

}

```

I thought that the Dictionary would be accessible throughout the public class but that doesn’t seem to be so. I don’t understand why the key becomes undefined when accessed from another function. What do I need to do to reach “dict” from within the finishQuestion() function?
