开发者

Drawing line without mxml (with ActionScript)

开发者 https://www.devze.com 2023-02-11 07:54 出处:网络
hai i want to draw a line with actionscript . Can anyone give me a hint Here is my code <?xml version=\"1.0\" encoding=\"ut开发者_如何学JAVAf-8\"?>

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

<?xml version="1.0" encoding="ut开发者_如何学JAVAf-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()"/>

`


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);
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消