不使用 mxml 绘制线条(使用 ActionScript)

发布于 2024-10-17 16:14:11 字数 724 浏览 6 评论 0原文

海我想用动作脚本画一条线。谁能给我一个提示 这是我的代码

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

    <fx:Script>
        <![CDATA[

        private function drawLine():void 
        {
            var myShape:Shape =new Shape();
            myShape=new Shape() ;
            myShape.graphics.lineStyle(2, 0x990000, .75);
            myShape.graphics.moveTo(10, 10);

            myShape.graphics.lineTo(25, 45);

        }

        ]]>
    </fx:Script>

<s:Button label="myButton" click="drawLine()"/>

`

hai i want to draw a line with actionscript . Can anyone give me a hint
Here is my code

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

    <fx:Script>
        <![CDATA[

        private function drawLine():void 
        {
            var myShape:Shape =new Shape();
            myShape=new Shape() ;
            myShape.graphics.lineStyle(2, 0x990000, .75);
            myShape.graphics.moveTo(10, 10);

            myShape.graphics.lineTo(25, 45);

        }

        ]]>
    </fx:Script>

<s:Button label="myButton" click="drawLine()"/>

`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2024-10-24 16:14:11

请注意,当您使用 myShape.graphics.moveTo 时,您并不是在应用程序本身上绘图,因为 Graphic 对象适用于您所使用的 Shape。创建的。

目前,您已将形状创建为内存中的新对象,并在其上绘制了一条线。

 _____________           _____________
|             |         | __          |  
|             |         ||\ | <-shape |  
|             |         ||_\|         |  
|             |         |             |  
| Application |         | Memory      |  
|             |         |             |  
|_____________|         |_____________|

为了使其显示在您的应用程序中,您仍然需要使用 addChild 将形状添加为应用程序或组件的子项。 Adobe 参考链接

 _____________           _____________
| __          |         |             |   
||\ | <-shape |         |             |   
||_\|         |         |             |  
|             |         |             |  
| Application |         | Memory      |  
|             |         |             |  
|_____________|         |_____________|

尝试使用 this.addChild 它应该添加您的形状,但请记住您在 Shape 对象上绘制的坐标不适合您的应用程序。

private function drawLine():void 
{
    var myShape:Shape = new Shape();
    myShape = new Shape() ;
    myShape.graphics.lineStyle(2, 0x990000, .75);
    myShape.graphics.moveTo(10, 10);

    myShape.graphics.lineTo(25, 45);
    this.addChild(myShape);
}

Notice that when you use the myShape.graphics.moveTo you are not drawing on the application itself because the Graphic object is for the Shape that you created.

Currently you have created the shape as a new object in memory and drawn a line on it.

 _____________           _____________
|             |         | __          |  
|             |         ||\ | <-shape |  
|             |         ||_\|         |  
|             |         |             |  
| Application |         | Memory      |  
|             |         |             |  
|_____________|         |_____________|

For it to show up in your application, you still need to use addChild to add the shape as a child of you Application or Component. Adobe Reference Link

 _____________           _____________
| __          |         |             |   
||\ | <-shape |         |             |   
||_\|         |         |             |  
|             |         |             |  
| Application |         | Memory      |  
|             |         |             |  
|_____________|         |_____________|

Try using this.addChild it should add your shape but remember that the coordinates that you drew on where for the Shape object not for you application.

private function drawLine():void 
{
    var myShape:Shape = new Shape();
    myShape = new Shape() ;
    myShape.graphics.lineStyle(2, 0x990000, .75);
    myShape.graphics.moveTo(10, 10);

    myShape.graphics.lineTo(25, 45);
    this.addChild(myShape);
}
皇甫轩 2024-10-24 16:14:11

您可以直接使用spark.primitives.Line来获取具有各种样式和属性的任何线条。

        private function drawLine():void
        {
            var newLn:Line = new Line();
            newLn.xFrom = 50;
            newLn.xTo = 200;
            newLn.y = 100;
            newLn.stroke = new SolidColorStroke(0xFF0000, 2);
            addElement(newLn);
        }

哈特哈,
FT任务

You can use directly spark.primitives.Line to get any line with all sorts of styles and properties.

        private function drawLine():void
        {
            var newLn:Line = new Line();
            newLn.xFrom = 50;
            newLn.xTo = 200;
            newLn.y = 100;
            newLn.stroke = new SolidColorStroke(0xFF0000, 2);
            addElement(newLn);
        }

HTH,
FTQuest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文