不使用 mxml 绘制线条(使用 ActionScript)
海我想用动作脚本画一条线。谁能给我一个提示 这是我的代码
<?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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,当您使用
myShape.graphics.moveTo
时,您并不是在应用程序本身上绘图,因为Graphic
对象适用于您所使用的Shape
。创建的。目前,您已将形状创建为内存中的新对象,并在其上绘制了一条线。
为了使其显示在您的应用程序中,您仍然需要使用
addChild
将形状添加为应用程序或组件的子项。 Adobe 参考链接尝试使用 this.addChild 它应该添加您的形状,但请记住您在 Shape 对象上绘制的坐标不适合您的应用程序。
Notice that when you use the
myShape.graphics.moveTo
you are not drawing on the application itself because theGraphic
object is for theShape
that you created.Currently you have created the shape as a new object in memory and drawn a line on it.
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 LinkTry 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.您可以直接使用spark.primitives.Line来获取具有各种样式和属性的任何线条。
哈特哈,
FT任务
You can use directly spark.primitives.Line to get any line with all sorts of styles and properties.
HTH,
FTQuest