11

I am migrating an application from Flex 3 to Flex 4. In some cases there are popup windows of which the width and height is bound to the application width and height.

width="{Application.application.width - 24}" 
height="{Application.application.height - 32}"

Application.application is deprecated in 4.0. so I have replaced this with

width="{FlexGlobals.topLevelApplication.width - 24}" 
height="{FlexGlobals.topLevelApplication.height - 32}"

Now the compiler gives the warning that data bindings cannot be detected for topLevelApplication.

Data binding will not be able to detect assignments to "topLevelApplication"

My question is: Is there another (bindable) property somewhere that I can use to get the same functionality as before?

Bocaxica
  • 3,911
  • 3
  • 37
  • 54
  • Is there a reason you need it to be bindable? I don't think the height and width values of topLevelApplication change unless the swf or the browser are resized at which point all of your controls would be redrawn anyhow (unless I'm mistaken of course). – Jason Towne Dec 21 '10 at 21:36

6 Answers6

21

Just create a variable of type object and make it bindable :

[Bindable]
private var application:Object = FlexGlobals.topLevelApplication;

And then use the variable.

height="{application.height}"
Mahima
  • 226
  • 1
  • 2
  • 2
    this makes the warning go away, but it is redundant and and it does NOT reflect any changes to the value you assign to the variable. This fix is misleading. – jediz Oct 01 '13 at 11:52
3

If you use {this.screen.height} your warnings should go away.

Tim

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
Tim
  • 80
  • 3
2

I was stuck for half an hour and found out that Bindable only works with a capital 'B', I did it and it solved my problem.

So, instead of bindable just write Bindable as the referred class is bindable.Bindable.

Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
2

This should work with a cast:

height="{(FlexGlobals.topLevelApplication as Application).height - 32}"

The reason why it isn't working with your current code is because FlexGlobals.topLevelApplication is typed as an Object.

James Ward
  • 29,283
  • 9
  • 49
  • 85
  • Hi James, I have tried this, but still getting the warnings. Any other options? Thanks. – Bocaxica Dec 21 '10 at 14:56
  • I should have read the error better. It can't bind to "topLevelApplication" which actually isn't bindable on FlexGlobals. That is a bummer. Maybe you can bind to systemManager.height instead. – James Ward Dec 23 '10 at 20:33
1

i was struggling with a similar warning, but instead of an object problem (wich is solved with the [Bindable] prefix) i was using a VBox. I needed to change the source of an image depending on how many childs my vbox has. So the solution to this is only using "this" lol. here's an example:

<mx:Image width="24" height="24" source="{this.vbBox1.getChildren().length>1 ?    'assets/icons/forwardDisable.png':'assets/icons/forward.png'}"/>

If you dont use "this" the IDE will show you a warning similar to the one that you have with the object. I hope it helps others!

Best Regards

0

Create a bindable variable type of your application i.e myApp to obtain all the variable defined in myApp or code completion:

[Bindable]
private var globals:myApp = FlexGlobals.topLevelApplication as myApp;

And then use the variable.

height="{globals.height}"