Reputation: 21
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()"/>
`
Upvotes: 2
Views: 3465
Reputation: 546
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
Upvotes: 4
Reputation: 2739
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);
}
Upvotes: 6