简体   繁体   English

Flex图像消失

[英]Flex Image Disappears

I am actually just learning flex, and i am getting confused with some parts. 我实际上只是在学习flex,而我对某些部分感到困惑。 The problem is that the background image i have set in the skin works fine until i add more elements, it then just becomes a white background rather than laying the elements over the top. 问题是,我在皮肤中设置的背景图像可以正常工作,直到我添加更多元素,然后它才变成白色背景,而不是将元素放在顶部。

I am starting to think im misunderstanding how this works. 我开始误以为这是如何工作的。 I don't understand why i need to have <s:Group id="contentGroup" /> for the image to show in the first place...this just seems like a redundant tag? 我不明白为什么我需要具有<s:Group id="contentGroup" />才能使图像首先显示...这似乎是一个多余的标记?

Here is the main code and the skin: 这是主要代码和外观:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" width="800" height="523" maxWidth="800" maxHeight="523" initialize="httpService.send()" showStatusBar="false" backgroundColor="white" backgroundAlpha="1">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;

            public var returnData:ArrayCollection;

            protected function httpService_handler(event:ResultEvent):void{
                returnData = event.result.people.person;

            }
        ]]>
    </fx:Script>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";

    </fx:Style> 
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:HTTPService id="httpService" url="" result="httpService_handler(event)" />
    </fx:Declarations>

    <s:BorderContainer borderVisible="false" mouseDown="nativeWindow.startMove();" skinClass="MainStyle" width="800" height="523" id="container" >
        <s:HGroup left="100" top="100" id="newsSlider" width="100" height="100">
            <s:Label>
                <s:text>Test</s:text>
            </s:Label>
        </s:HGroup>
    </s:BorderContainer>
</s:WindowedApplication>

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <!-- host component -->
    <fx:Metadata>
        [HostComponent("spark.components.BorderContainer")]
    </fx:Metadata>

    <!-- states -->
    <s:states>
        <s:State name="disabled" />
        <s:State name="normal" />
    </s:states>

    <!-- SkinParts
    name=contentGroup, type=spark.components.Group, required=false
    -->
    <s:Group id="contentGroup" width="800" height="523">
        <s:BitmapImage id="bg" source="@Embed('/School Catchup/libs/images/App-BG8.png')" scaleMode="stretch" left="0" top="0" right="0" bottom="0" width="800" height="523" />
    </s:Group>
</s:Skin>

contentGroup is the only "skinPart" of the SkinnableContainer component, which is the base class for BorderContainer. contentGroupSkinnableContainer组件的唯一“ skinPart”,它是BorderContainer的基类。 It's not a required skinpart (the compiler would've thrown you an error otherwise in your previous version where you didn't have the skinpart in your skin). 它不是必需的skinpart(否则,在以前的版本中,如果皮肤中没有skinpart,编译器会向您抛出错误)。

What is a skinPart? 什么是skinPart?

It's a contract between the host component and its skin. 这是宿主组件与其皮肤之间的契约。 Essentially the host component is instructing the skin (through metadata) that it needs this and this and that element (skin part) in order to function correctly. 本质上,主机组件正在(通过元数据)指示皮肤它需要此元素以及此元素和元素(皮肤部分)才能正常运行。 Some of these elements are absolutely required for the component to function, some are optional. 这些元素中的某些绝对是组件正常运行所必需的,而某些则是可选的。

What is the contentGroup skinpart? contentGroup skinpart是什么?

It's the container element to which SkinnableContainer will add its nested elements. 这是SkinnableContainer将其嵌套元素添加到的容器元素。 As an example: 举个例子:

<s:SkinnableContainer>
    <s:Label text="hello"/>
</s:SkinnableContainer>

behind the scenes, the Label instance will be added to the contentGroup skinpart of SkinnableContainer's skin. 在幕后, Label实例将添加到SkinnableContainer皮肤的contentGroup skin部分。

So how do I get my example to work? 那么如何使我的榜样发挥作用呢?

As you can see from what I explained before, the contentGroup element is just a placeHolder in the skin. 从我之前的解释中可以看到, contentGroup元素只是皮肤中的placeHolder。 If you want to add "chrome" to your custom component, add it outside that Group: 如果要将“ chrome”添加到自定义组件,请将其添加到该组之外:

<s:BitmapImage id="bg" source="@Embed('/School Catchup/libs/images/App-BG8.png')" scaleMode="stretch" left="0" top="0" right="0" bottom="0" width="800" height="523" />

<s:Group id="contentGroup" width="800" height="523"/>

This will display the image behind the contentGroup and your Labels will now be added to it without removing the BitmapImage that you declared in there. 这将在contentGroup后面显示图像,并且现在将在不删除您在其中声明的BitmapImage的情况下将Labels添加到其中。

This is just a short explanation of the skinning mechanism in the context of your needs. 这只是在您需要的情况下对换肤机制的简短说明。 I suggest you do some research on this specific topic to really understand how it works. 我建议您对此特定主题进行一些研究,以真正了解其工作原理。

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

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