Maxim Razin
Maxim Razin

Reputation: 9466

Disable warning only in one place

In an MXML code

<fx:Script>
   public var data:ArrayCollection = new ArrayCollection();
</fx:Script>
<s:DataGroup dataProvider="{data}" />

I'm getting a warning:

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

I know that the data provider will be never changed in this case, and want to suppress this warning in this case, but I don't want to completely disable it, -show-binding-options=false in all project is not an option.

How to disable a warning only in one place? Disabling for the whole file is not so good, but acceptable.

Upvotes: 3

Views: 779

Answers (2)

eddipedia
eddipedia

Reputation: 411

Instead of using <fx:Script></fx:Script> you could use <fx:Declarations></fx:Declarations>. Any object declared in that MXML element is bindable implicitly. Here's how your code will look like then:

<fx:Declarations>
    <s:ArrayCollection id="data" />
</fx:Declarations>

<s:DataGroup dataProvider="{data}" />

Additionally it becomes much more readable and there's no mix of ActionScript and MXML. Because your collection is declared as public it makes difference whether to use ActionScript with [Bindable] or using MXML.

BTW, a general recommendation for cleaner code is to separate ActionScript completely from MXML. For instance in my projects I create a separate ActionScript file for each MXML component in the form <NameOfComponent>Includes.as.

Upvotes: 0

martineno
martineno

Reputation: 2635

How about just making your data variable bindable? Something like:

<fx:Script>
   [Bindable]
   public var data:ArrayCollection = new ArrayCollection();
</fx:Script>
<s:DataGroup dataProvider="{data}" />

Upvotes: 2

Related Questions