PDA

View Full Version : simple variable scope


eddjc
08-30-2009, 02:45 PM
Hey all,

Just trying to do something that seems like it should be simple-

<mx:Script>
<![CDATA[

[Bindable]
private var low:String = application.parameters.low;

/* (left out for debugging)
[Bindable]
private var high:String = application.parameters.high;

*/

ExternalInterface.call("console.log", low);

]]>
</mx:Script>

That's just in the base Application element. for some reason, I get the error:

1120:Access of undefined property low

Any ideas why? I've tried removing the [Bindable], changing it to the public variable, getting rid of the word private, everything! Something I'm just not seeing?

Many thanks
Edd

wvxvw
08-30-2009, 06:07 PM
<mx:Script/> is the place where you put declarations, you shouldn't execute code there, it's the same as if you did something like this in AS:
package {
...
public class Foo {
...
ExternalInterface.call("console.log", low);
...
public function Foo() {
}}}

eddjc
08-30-2009, 06:35 PM
I'm not sure I follow you - although have worked out that the ExternalInterface command doesn't work from within a class definition (not sure why!) I did however manage to get this particular script working - the problem was that until the application os loaded, the parameters aren't available -

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:controls="com.fxcomponents.controls.*"
backgroundColor="#444444" themeColor="#628CAF" backgroundGradientAlphas="{[0, 0]}"
paddingTop="0"
paddingLeft="0"
paddingRight="0"
paddingBottom="20"
creationComplete="initVars()">
<mx:Script>
<![CDATA[

[Bindable]
private var appSource:String = "YDA medium.flv";


[Bindable]
private var low:String;

[Bindable]
private var high:String;


function initVars():void {

low = Application.application.parameters.low;
high = Application.application.parameters.high;

ExternalInterface.call("console.log", high);
fxVid.source = low;

fxVid.low = low;
fxVid.high = high;


}

]]>
</mx:Script>

but then you may be right - that might just work because it's inside a function! So in the MXML file code should be restricted to variable declaration, like an interface?

Many thanks
Edd

wvxvw
08-30-2009, 07:22 PM
>> So in the MXML file code should be restricted to variable declaration, like an interface?
Yes, this is close, but not exact.
Try adding -keep optional compiler argument to see what comes out of your MXML files, this would explain it better.

eddjc
08-30-2009, 10:21 PM
er... how do I do that from Flex builder?

Many thanks
Edd

wvxvw
08-30-2009, 11:04 PM
See the picture:

eddjc
08-31-2009, 08:18 AM
ah! Fascinating!

Many thanks
Edd