繁体   English   中英

如何在Flash Builder中使用Flex中的ActionScript在矢量图形中分别更改填充和描边

[英]How do I change the fill and stroke separately in a vector graphic using actionscript in flex in flash builder

如果我有一个填充有蓝色和橙色笔触的矩形,如何使用actioncript将描边更改为黑色,将填充更改为红色。

当我使用以下代码时,它将整个矩形更改为0x008000(绿色)。 填充是覆盖笔触,还是将填充和描边都更改为0x008000(绿色)。

var myColor:ColorTransform = myRectangle.transform.colorTransform;

                    savedColor = myRectangle.transform.colorTransform;

                    myColor.color = 0x008000;

                    myRectangle.setColorTransform(myColor);

我注意到,当我转换回保存的颜色时,它会恢复我想要的原始填充和描边颜色。

            myRectangle.setColorTransform(savedColor);

第一次更改时,我不能将矩形更改为其他颜色以进行填充和描边,而无需保存。

我想要做的是将填充和笔触设置为不同的颜色,并控制填充是否覆盖笔触。

请在下面看到一个简单的flex程序,您可以使用它来进行调整并给出答案:

预先感谢劳伦斯

<?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="0" minHeight="0" usePreloader="true">
 <fx:Script>
        <![CDATA[
              public var savedColor:ColorTransform;
              protected function button1_clickHandler(event:MouseEvent):void
              {
                   var myColor:ColorTransform = GEN1.transform.colorTransform;
                    savedColor = GEN1.transform.colorTransform;
                    myColor.color = 0x008000;
                    GEN1.setColorTransform(myColor);
                    b1.visible = false;
                    b2.visible = true;
              }
              protected function button2_clickHandler(event:MouseEvent):void
              {
                    GEN1.setColorTransform(savedColor);
                    b2.visible = false;
                    b1.visible = true;
              }
        ]]>
  </fx:Script>

  <fx:Declarations>
  </fx:Declarations>
  <s:Group>
        <s:layout>
              <s:VerticalLayout paddingTop="10"/>
        </s:layout >
        <s:Group>
              <s:layout>
                    <s:HorizontalLayout/>
              </s:layout> 
              <s:Button id="b1" click="button1_clickHandler(event)"  label="Generator 1 ON"/>
              <s:Button id="b2" visible="false" click="button2_clickHandler(event)"  label="Generator 1 OFF"/>
        </s:Group>              
        <s:Group  >
              <s:Graphic version="2.0"  xmlns:d="http://ns.adobe.com/fxg/2008/dt" xmlns:fc="http://ns.adobe.com/flashcatalyst/2009"  viewHeight= "645" viewWidth= "1043">
                    <s:Path winding="evenOdd" data="M 341 30 C 341 19 350 10 361 10 C 372 10 381 19 381 30 C 381 41 372 50 361 50 C 350 50 341 41 341 30 Z " blendMode="normal" alpha="1" id="GEN1">
                          <s:fill>
                                <s:SolidColor color="#b6b6b6"/>
                          </s:fill>
                          <s:stroke>
                                <s:SolidColorStroke color="#333333" weight="4" caps="none"/>
                          </s:stroke>
                    </s:Path>
              </s:Graphic>                                    
        </s:Group>
  </s:Group>
</s:Application>

给他们ID:

          <s:Graphic version="2.0"  xmlns:d="http://ns.adobe.com/fxg/2008/dt" xmlns:fc="http://ns.adobe.com/flashcatalyst/2009"  viewHeight= "645" viewWidth= "1043">
                <s:Path winding="evenOdd" data="M 341 30 C 341 19 350 10 361 10 C 372 10 381 19 381 30 C 381 41 372 50 361 50 C 350 50 341 41 341 30 Z " blendMode="normal" alpha="1" id="GEN1">
                      <s:fill>
                            <s:SolidColor color="#b6b6b6" id="fill"/>
                      </s:fill>
                      <s:stroke>
                            <s:SolidColorStroke color="#333333" weight="4" caps="none" id="stroke"/>
                      </s:stroke>
                </s:Path>
          </s:Graphic>     

然后在ActionScript中,只需更改类的属性即可:

fill.color = 0x000000;
stroke.color = 0xffffff;

暂无
暂无

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

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