简体   繁体   English

组元素在Adobe Flex 3中不起作用

[英]Group Element not working in adobe flex 3

i am trying to create multiple tab with close button in adobe flex 3. for this i have created parent and child object. 我正在尝试使用Adobe Flex 3中的关闭按钮创建多个选项卡。为此,我创建了父对象和子对象。 parent object for tab and child object for close button and place both object in Group container grammatically in function called "addButton()". 选项卡的父对象和关闭按钮的子对象,然后将两个对象按语法放在“ addButton()”函数中的“组”容器中。 my code working fine in adobe flex 4.5 but not working in adobe flex 3. due to some reason i have to use adobe flex 3. i have try other container like: HBox, controllbar etc but these are unable to make proper tab view. 我的代码在adobe flex 4.5中可以正常工作,但在adobe flex 3中不能正常工作。由于某些原因,我不得不使用adobe flex 3。 below is code. 下面是代码。

 <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="127" minHeight="34" backgroundColor="#F4E8E8">
    <s:layout>
        <s:FormItemLayout/>
    </s:layout>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>


<fx:Script>
    <![CDATA[
    import mx.graphics.SolidColor;

    import spark.components.Button;

    import spark.components.Group;

    import spark.primitives.Rect;

    public function addButton():void {

        //Child Object
        var myButton:Button = new Button();
        myButton.id = "dd";
        myButton.label="X";
        myButton.width = 40;
        myButton.height = 20;
        myButton.depth =1;
        myButton.x=50;
        myButton.setStyle("color",'red');
        myButton.addEventListener(MouseEvent.CLICK, btn);

        //Parent Object
        var lble:Group = new Group();
        var solidColor:SolidColor = new SolidColor(0xFF0000);
        var rec:Rect = new Rect();

        rec.fill = solidColor;
        rec.percentWidth = 100;
        rec.percentHeight = 100;
        lble.width = 127;
        lble.height = 34;
        lble.depth =0;
        lble.addElement(rec);
        lble.addEventListener(MouseEvent.CLICK, lable);
        lble.addElement(myButton);
        myGroup.addElement(lble);

    }

    private function btn(e:Event):void {
        e.stopPropagation();
        jj.text = 'Text For Button';
    }

    private function lable(e:Event):void {
        kk.text = "Text For Label";
    }

    ]]>
</fx:Script>

<s:HGroup id="myGroup">
    <s:Button width="126" height="34" click="addButton();" label="Click" skinClass="spark.skins.spark.ButtonSkin"/>
</s:HGroup>

<s:Label id="jj" x="14" y="150" width="1200" height="50" backgroundColor="gray" text="Button"/>
<s:Label id="kk" x="14" y="69" width="1200" height="50" backgroundColor="gray" text="Label"/>

</s:Application>  

please help me 请帮我

1) Group Element (container) Not working in Flex 3 : 1)组元素(容器)在Flex 3中不起作用:

Definitely it won't work in Flex 3, there is major difference between Flex 3 and Flex 4 or mx(halo) and spark(Gumbo) respectively. 绝对不能在Flex 3中使用,Flex 3和Flex 4或分别为mx(halo)和spark(Gumbo)之间存在主要区别。 You need to have clear understanding of both the things if you want to convert a component from spark to mx or vice versa. 如果要将组件从spark转换为MX,反之亦然,则需要对这两种情况都有清楚的了解。

Here is a nice article that explain the Difference between Flex 3 and Flex 4 这是一篇很好的文章,解释了Flex 3和Flex 4之间区别

2) I am trying to create multiple tab with close button in adobe flex 3: 2)我试图在Adobe Flex 3中使用关闭按钮创建多个标签:

Since Flex is a 10 years matured framework there are plenty of open source components available out there you don't have to create a component from scratch. 由于Flex是一个10年成熟的框架,因此有许多可用的开源组件,您无需从头开始创建组件。 But i appreciate your attempt to do it on your own way. 但是,我感谢您以自己的方式做到这一点。

Have a look in to this before you start creating components 开始创建组件之前请先对此进行了解

Flex 3 Component Life cycle Flex 3组件生命周期

Flex 4 Component Life cycle and Creating Advanced spark components Flex 4组件生命周期和创建高级Spark组件

Spark Tab with close button 带关闭按钮的Spark Tab

Flex 3 SuperTabNavigator FlexLib component Flex 3 SuperTabNavigator FlexLib组件

Flex: How to add a tab close button for TabNavigator component Flex:如何为TabNavigator组件添加选项卡关闭按钮

You can use Box as mx component. 您可以将Box用作MX组件。 Here is what you can do in flex 3: 这是您在flex 3中可以执行的操作:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
    import mx.containers.Box;

    public function addButton():void {

        //Child Object
        var myButton:Button = new Button();
        myButton.id = "dd";
        myButton.label="X";
        myButton.width = 40;
        myButton.height = 20;
        myButton.x=50;
        myButton.setStyle("color",'red');
        myButton.addEventListener(MouseEvent.CLICK, btn);

        //Parent Object
        var box:Box = new Box();
        box.setStyle("borderThickness", "1");
        box.setStyle("borderStyle", "solid");
        box.setStyle("borderColor", "black");
        box.setStyle("backgroundColor", "0xFF0000");
        box.width = 127;
        box.height = 34;
        box.addEventListener(MouseEvent.CLICK, lable);
        box.addChild(myButton);
        myHBox.addChild(box);

    }

    private function btn(e:Event):void {
        e.stopPropagation();
        jj.text = 'Text For Button';
    }

    private function lable(e:Event):void {
        kk.text = "Text For Label";
    }

    ]]>
</mx:Script>

<mx:HBox id="myHBox">
    <mx:Button width="126" height="34" click="{addButton();}" label="Click"/>
</mx:HBox>

<mx:Label id="jj" x="14" y="150" width="1200" height="50" text="Button"/>
<mx:Label id="kk" x="14" y="69" width="1200" height="50" text="Label"/>

</mx:Application>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM