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()"/>
`
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With