flash 调用 脚本_Flash脚本-创建Flash画板

flash 调用 脚本

Flash MX now has the ability to draw lines and curves dynamically, by using the new drawing methods of the MovieClip object. I will teach you how to create a simple line drawing application using the built in Flash drawing API.

通过使用MovieClip对象的新绘制方法,Flash MX现在可以动态绘制直线和曲线。 我将教您如何使用内置的Flash绘图API创建简单的线条画应用程序。

Download the sample files here.

在此处下载示例文件

使用的功能 (Functions Used)

The main functions I am using for this application are:

我为此应用程序使用的主要功能是:

myMovieClip.createEmptyMovieClip (instanceName, depth)

This method creates an empty movie clip as a child of an existing movie clip. This method behaves similarly to the attachMovie method, but you don’t need to provide an external linkage name for the new movie clip. The registration point for a newly created empty movie clip is the upper left corner. This method fails if any of the parameters are missing.

此方法创建一个空的影片剪辑作为现有影片剪辑的子级。 此方法的行为类似于attachMovie方法,但是您不需要为新的影片剪辑提供外部链接名称。 新建的空白影片剪辑的注册点在左上角。 如果缺少任何参数,此方法将失败。

myMovieClip.lineStyle (thickness,rgb,alpha)

This method specifies a line style that Flash uses for subsequent calls to the lineTo and curveTo methods until you call lineStyle with different parameters. You can call the lineStyle method in the middle of drawing a path to specify different styles for different line segments within a path.

此方法指定Flash用来随后调用lineTocurveTo方法的线型,直到您使用不同的参数调用lineStyle为止。 您可以在绘制路径的中间调用lineStyle方法,以为路径中的不同线段指定不同的样式。

myMovieClip.moveTo (x, y)

This method moves the current drawing position to (x, y). If any of the parameters are missing, this method fails and the current drawing position is not changed.

此方法将当前绘图位置移动到(x, y) 。 如果缺少任何参数,则此方法将失败,并且当前图形位置不会更改。

myMovieClip.lineTo (x, y)

This method draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y). If the movie clip that you are drawing in contains content that was created with the Flash drawing tools, – calls to lineTo are drawn underneath the content. If you call the lineTo method before any calls to the moveTo method, the current drawing position defaults to (0, 0). If any of the parameters are missing, this method fails and the current drawing position is not changed.

此方法使用当前线型从当前绘制位置到(x, y)绘制一条线; 然后将当前绘图位置设置为(x, y) 。 如果您要绘制的影片剪辑包含使用Flash绘制工具创建的内容,则在该内容下方绘制对lineTo调用。 如果您调用lineTo对moveTo方法调用的任何方法之前,当前的绘画位置默认为(0, 0) 如果缺少任何参数,则此方法将失败,并且当前图形位置不会更改。

流程 (The Process)

1. Create a new movie and select the first frame.

1.制作新电影,然后选择第一帧。

Open the actionscript window and enter:

打开动作脚本窗口,然后输入:

createEmptyMovieClip("Line",1);

The above code creates a empty movieclip with a instance name called Line with a depth of 1

上面的代码创建一个空的动画片段,其实例名称为Line,深度为1

2. Enter the code below to set the line style:

2.输入以下代码来设置线条样式:

Line.lineStyle(1,0x000000,100);

The above code sets the line style dynamically. The Line will be 1 point thick and have a hex color of black , and an alpha value of 100.

上面的代码动态设置线条样式。 线将是1点粗,并且具有黑色的十六进制颜色和100的alpha值。

3. Enter the code which will draw the line:

3.输入将画线的代码:

onMouseDown = function (){
 Line.moveTo(_xmouse, _ymouse);
 onMouseMove = function (){
 Line.lineTo(_xmouse, _ymouse);}
}
onMouseUp=function(){
 onMouseMove=null;
}

The above code will draw the line when you click and drag the mouse.

当您单击并拖动鼠标时,以上代码将绘制直线。

Let’s see how each line works:

让我们看看每一行是如何工作的:

onMouseDown = function (){

The function onMouseDown is activated when you click the mouse button.

单击鼠标按钮时, onMouseDown功能被激活。

Line.moveTo(_xmouse, _ymouse);

This moves the line to the starting point, which will be directly where you clicked. _xmouse and _ymouse are the x and y position of the mouse.

这会将线移动到起点,该起点将直接位于您单击的位置。 _xmouse_ymouse是鼠标的x和y位置。

onMouseMove = function (){

The function onMouseMove is activated only when you move the mouse.

仅当您移动鼠标时, onMouseMove功能才被激活。

Line.lineTo(_xmouse, _ymouse);}

This creates the line to the point where ever your mouse is dragged.

这将创建一条直线,直到您的鼠标被拖动到的位置。

onMouseUp=function(){

The function onMouseUp is activated when you release the mouse button.

释放鼠标按钮时, onMouseUp功能将被激活。

onMouseMove=null;

This function turns off the onMouseMove() function so that the line will not be drawn again until the user clicks the mouse button again.

此函数关闭onMouseMove()函数,以便在用户再次单击鼠标键之前不会再次绘制线条。

This is the full code:

这是完整的代码:

createEmptyMovieClip("Line",1);
Line.lineStyle(1,0x000000,100);
onMouseDown = function () {
 Line.moveTo(_xmouse, _ymouse);
}
onMouseMove = function ()  {  
 Line.lineTo(_xmouse, _ymouse);}
}
onMouseUp=function() {
 onMouseMove=null;
}
//The above code should be entered in the first frame of the movie

Test the movie. Click and drag to see the line being drawn. If you have followed the steps correctly you will get the same result as mine.

测试电影。 单击并拖动以查看正在绘制的线。 如果您正确地遵循了这些步骤,您将获得与我相同的结果。

翻译自: https://www.sitepoint.com/create-flash-sketchpad/

flash 调用 脚本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值