我有一个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>
我想动态地为alpha
设置myRect
的值。是否可以使用Actionscript设置alpha
?如果是,如何访问alpha
属性?
我认为这样的事情会起作用,但我收到错误Access of undefined property SolidColorStroke
:
searchRect.stroke.SolidColorStroke.alpha=1;
答案 0 :(得分: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>