Flex custom component doesn't accept Script: Multiple initializer values for default property, 'text', of type 'String'

◇◆丶佛笑我妖孽 提交于 2019-12-10 16:03:38

问题


I'm using Flex 4 and Flash Builder 4. I just want to learn to create components and I created an mxml component as follows and included it in my application:

<?xml version="1.0" encoding="utf-8"?>
<s:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
    </fx:Script>
</s:TextInput>

If I take out the fx:Script tags it works, but as soon as I have those tags (regardless of whether any actual code is in there) I get the error: "Flex custom component doesn't accept script: Multiple initializer values for default property, 'text', of type 'String'."

Why would that be? Is script not allowed in components?


回答1:


this is a known bug SDK-25184. Milestone is the next Flex SDK Hero Release. You still can use mxml if you explicitly set the text property.

<?xml version="1.0" encoding="utf-8"?>
<s:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx"
             text="">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:TextInput>

Thanks.




回答2:


If you change TextInput to Button it will be OK.

The problem is that TextInput treats Script as a value for text property. I believe it is a compiler bug.




回答3:


Another way around this is to extend TextInput using actionscript rather than mxml:

package
{
    import spark.components.TextInput;

    public class TestTextInput extends TextInput
    {
        public function TestTextInput()
        {
            super();
        }
    }
}


来源:https://stackoverflow.com/questions/3139486/flex-custom-component-doesnt-accept-script-multiple-initializer-values-for-def

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!