views:

112

answers:

2

I have a simple object defined by an object literal, and have a couple functions assigned to this object. Inside the functions, I try to access global variables, and it only gets undefined. The Flex debugger tells me the variables are just right up the scope tree.

Yes, I know I can access Thing by using 'this', that doesn't solve my scope issue though.

Project Flex Compiler Settings: Flex SDK 3.4, Require Flash Player 10.x.

Example:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="Thing.bling();">

    <mx:Script>
     <![CDATA[
      var Thing:Object = {
       doStuff: function():void {
        trace(blah); //blah is undefined
       },
       bling: function():void {
        Thing.doStuff(); //Thing is undefined
       },

      };
     ]]>
    </mx:Script>

    <mx:Panel id="blah">

    </mx:Panel>
</mx:Application>
+1  A: 

I'm not sure what your trouble is, but I cut and paste your exact code into a new Flex project and despite a simple syntax error (extra trailing comma in the Thing declaration) it traced what I would expect:

Test0.blah

(Given that my project name is Test and the panel blah is the first object).

I used Flex 3.3 then tried Flex 3 both on Flash Player 10,0,22,87

edit:
I can reproduce now if I alter the project properties by following the instructions in the comments:
Flex Builder -> Properties -> Flex Compiler -> Require Flash Player Version -> 10.0.0

With this setting the behaviour does not appear in Flex 3.0 but does appear in 3.2, 3.3 and 3.4.

I suggest this is a bug and you should find a way to work around it.

James Fassett
Brand new project for me gives Error #1069: Property ::Thing not found on Object and there is no default value. Using in Flex 3.4, Flash Player 10.0.0
seanmonstar
Just downloaded SDK 3.4.0.6955 and it traces out for me the correct Test0.blah. Are you using Flex Builder? The only difference is our Flash Player versions. Sorry, not much else I can do for you if I cannot reproduce.
James Fassett
I am using Flex Builder. Under Project -> Flex Compiler, do you have it require Flash Player 10+? If it's checked for Flash Player 9, it works, but I need 10.
seanmonstar
I can reproduce now. Please update the original problem description to add that you need to update the required Flash version to reproduce.It doesn't happen on SDK 3, but it appears in SDK 3.2, 3.3 and 3.4 under those circumstances. I can only guess why, and my guess would be that there were changes in how the MXML is converted to ActionScript that screws up object creation.I would submit this as a bug to Adobe.
James Fassett
It felt like a bug. But it felt so blatant, I figured there must have just been a change in doing things. And that I was stupid and someone could easily point it out. Thanks for helping.
seanmonstar
A: 

try

            var Thing:Object;
            Thing = {
                    doStuff: function():void {
                            trace(blah); //blah is undefined
                    },
                    bling: function():void {
                            Thing.doStuff(); //Thing is undefined
                    },

            };

just a guess ... but i experienced a lot of problems where this was neccessary ... too drunk and to tired to try out whether this solves the problem ... but for you, it should be just the beginning of the evening/night ... :D

back2dos
nope, that even throws compiler errors
seanmonstar