Why mx: states cannot be resolved to implement a component?

From time to time, I get an error when setting states in the MXML file. The error I get says that mx: states cannot be resolved to implement the component.

I read at the following URL that this problem is caused by component expansion - something discards the compiler's ability to resolve mx: states. I do not understand why this should be, but I do not have my own answer. I also cannot get this approach to work with all my advanced components.

http://life.neophi.com/danielr/2007/01/could_not_resolve_to_a_compone.html

The workaround I came up with is not to use any namespace. So my code is as follows:

<states>...</states> 

but not:

 <mx:states>...</mx:states> 

The creation of this stranger (at least for me) is that the children of the tag do not have this problem. mx: states cannot be resolved, but its child mx: State can. And mx: SetProperty - a child of mx: State - is also allowed.

Can someone explain this and / or suggest a better solution to the problem than what I came up with?

By the way, I see the same problem with mx: transitions.

+4
source share
2 answers

If you have a custom component, you are likely to have it in a namespace other than mx. You are on the right track by deleting the namespace, but you do not need to do this. Consider the following example.

 <example:MyComponent xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:example="com.example.*"> </example:MyComponent> 

In this code, we have a custom component MyComponent in the com.example package. Now, how to add custom states? It is easy!

 <example:MyComponent xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:example="com.example.*"> <example:states> <mx:State name="CustomState"> </mx:State> </example:states> </example:MyComponent> 

Component properties, such as states, transitions, or even a label on a Button, can be created as children. These properties must use the same namespaces as the component instance. It doesn't matter where the property comes from the inheritance chain. Even if com.example.MyComponent extends mx.containers.Canvas, the states property will use the XML namespace in which MyComponent is defined.

In short, don't think of state properties like mx: states, because the prefix mx: property is simply inherited from the component. However, we need to use mx: when we define the actual state, because the class (not the property) and this class are defined in the mx namespace.

To continue step by step in the explanation, you can change the namespace http://www.adobe.com/2006/mxml as something other than mx.

 <zzz:VBox xmlns:zzz="http://www.adobe.com/2006/mxml"> <zzz:states> </zzz:states> </zzz:VBox> 

In this example, we will change mx to zzz. The state property should now have the zzz: prefix instead of mx :.

+17
source
 <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" backgroundColor="#f7f7f7" xmlns:common="com.americanexpress.voice.view.component.common.*"> <mx:states name="edit"> 

Why is this failing? I also found that this fails if I have multiple namespaces defined. Remove the problem <mx:

+1
source

All Articles