1

我有一个 Flex 应用程序,在其中我使用以下方法绘制一个矩形:

<s:Rect height="20" width="115" top="1" id="myRect">
    <s:stroke>
        <s:SolidColorStroke color="#FF0000" weight="2" alpha="0"/>
    </s:stroke>
</s:Rect>   

我想动态设置alphafor的值myRect。是否可以alpha使用 Actionscript 进行设置?如果是这样,如何访问该alpha属性?

我认为这样的事情会起作用,但我收到错误Access of undefined property SolidColorStroke

searchRect.stroke.SolidColorStroke.alpha=1;
4

1 回答 1

1

给出s:SolidColorStroke一个 id,如下所示:

<s:SolidColorStroke id="stroke"

然后你可以设置 alpha 如:

 stroke.alpha = 0.5;

此示例基于滑块更新 alpha:

滑块

<?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">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

    <s:Rect height="20"
            width="115"
            top="1"
            id="myRect">
        <s:stroke>
            <s:SolidColorStroke id="stroke"
                                color="#FF0000"
                                weight="2"
                                alpha="0" />
        </s:stroke>
    </s:Rect>

    <s:HSlider id="slider"
               valueCommit="{stroke.alpha = slider.value}"
               value="0.5"
               minimum="0"
               maximum="1"
               stepSize="0.1"
               snapInterval="0.1" />

</s:Application>
于 2012-06-27T00:55:00.530 回答