简体   繁体   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

If I have a rectangle which has a fill of blue and stroke of orange how can I change the stroke to black and the fill to red using actioncript. 如果我有一个填充有蓝色和橙色笔触的矩形,如何使用actioncript将描边更改为黑色,将填充更改为红色。

When I use the following code it changes the entire rectangle to 0x008000 (green). 当我使用以下代码时,它将整个矩形更改为0x008000(绿色)。 Either the fill is covering the stroke or it is changing both the fill and stroke to 0x008000 (green). 填充是覆盖笔触,还是将填充和描边都更改为0x008000(绿色)。

var myColor:ColorTransform = myRectangle.transform.colorTransform;

                    savedColor = myRectangle.transform.colorTransform;

                    myColor.color = 0x008000;

                    myRectangle.setColorTransform(myColor);

I notice when I convert back to the saved color it brings back the original fill and stroke colors as I want. 我注意到,当我转换回保存的颜色时,它会恢复我想要的原始填充和描边颜色。

            myRectangle.setColorTransform(savedColor);

I just can not change the rectangle to a different color for fill and for stroke when changing for the first time without being saved. 第一次更改时,我不能将矩形更改为其他颜色以进行填充和描边,而无需保存。

What I want to be able to do is set the fill and stroke to different colors and also control whether or not the fill will cover the stroke. 我想要做的是将填充和笔触设置为不同的颜色,并控制填充是否覆盖笔触。

Please see below a simple flex program one can use to tweak and give an answer back if you can figure it out: 请在下面看到一个简单的flex程序,您可以使用它来进行调整并给出答案:

Thanks in advance Lawrence 预先感谢劳伦斯

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

Give them IDs: 给他们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>     

Then in ActionScript just change the properties on the class: 然后在ActionScript中,只需更改类的属性即可:

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

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

相关问题 如何使用Flash Builder从FLEX Flash项目生成Flash投影仪文件? - How do I generate a flash projector file from my FLEX Flash project using Flash Builder? Flash Builder(Flex 4):如何将facebook-actionscript-api添加到我的项目中 - flash builder (flex 4): how can i add facebook-actionscript-api to my project Flash Builder:如何将Flex项目框架添加到ActionScript项目中? - Flash Builder: how to get flex project framework into ActionScript project? “状态”如何在Flash Builder和Flex中工作? - How do “States” work in Flash Builder and Flex? Flex - 如何在 Flash Builder 中进行计算 - Flex - How to do calculation in Flash Builder 如何更改Flash Builder 4.5用于ActionScript项目的目录名称? - How to change the directory name used by Flash Builder 4.5 for actionscript project? 如何更改Flash Builder生成HTML以在ActionScript中调用函数? - how to change the flash builder generate HTML to call function in actionscript? 如何允许Flex / Flash / Actionscript与javascript通信 - how do you allow javascript communications with Flex/Flash/Actionscript 如何使用ActionScript在Adobe Flex中更改状态? - How to change the state in Adobe Flex, using ActionScript? 如何从Java调用Flex / Flash / Actionscript方法? - How can I call a Flex/Flash/Actionscript method from Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM