使用Flex Hero mobile的绘图创建自定义组件

时间:2010-12-30 16:01:41

标签: flex mobile

我正在尝试使用以下适用于Android的Flex Mobile项目(在Flash Builder 4.5 Burrito中)创建一个在中间显示红色矩形的自定义组件 -

MyComp.mxml (没有错误):

<?xml version="1.0" encoding="utf-8"?>
<components:MobileApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:components="spark.components.*" 
    firstView="views.MyCompHome">
</components:MobileApplication>

views \ MyCompHome.mxml (没有错误):

<?xml version="1.0" encoding="utf-8"?>
<components:View 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:components="spark.components.*"
    xmlns:comps="comps.*"
    title="My Component">

    <comps:MyRect width="100%" height="100%"/>

</components:View>

问题 comps \ MyRect.mxml (有1个编译错误):

<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    width="100%" height="100%">

    <mx:Script>
        <![CDATA[
            private var rect:Shape = new Shape();

            override protected function createChildren():void {
                super.createChildren();
                trace('createChildren');

                rect.graphics.beginFill(0xFF0000);
                rect.graphics.drawRect(0, 0, 20, 20);
                addChild(rect);
            }

            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                trace('updateDisplayList(' + unscaledWidth + ', ' + unscaledHeight + ')');

                rect.x = unscaledWidth / 2;
                rect.y = unscaledHeight / 2;
            }
        ]]>
    </mx:Script>
</mx:UIComponent>

编译错误是:

Description Resource    Path    Location    Type
Could not resolve <mx:UIComponent> to a component implementation.   
MyRect.mxml /MyComp/src/comps   line 4  Flex Problem

即使我已将 c:\ Program Files \ Adob​​e \ Adob​​e Flash Builder Burrito \ sdks \ 4.5.0 \ frameworks \ libs \ mx \ mx.swc 添加到Flex Build Path(通过单击在项目属性对话框中“添加SWC”按钮。

1 个答案:

答案 0 :(得分:1)

我不认为UIComponent可用于MXML。尝试将MyRect.mxml更改为扩展UIComponent的ActionScript类(MyRect.as)。

编辑:我错了它可以在MXML中使用。您是否有理由不在组件中使用最新的命名空间?这似乎对我有用:

<mx:UIComponent 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>
    <![CDATA[
        private var rect:Shape = new Shape();

       ...