下载首页 | 资讯中心 | 文章分类 | 最近更新 | 排 行 榜 | 国产软件 | 国外软件 | 绿色软件 | 汉化补丁 | |
文章搜索: 分类 关键字
您的位置:首页软件学院 → Flash AS代码实例:仿贝塞尔曲线控制
Flash AS代码实例:仿贝塞尔曲线控制
来源:天极yesky 作者:jisekai 加入时间:2007-9-12 访问次数:0 [  ]
  本文中我们用Flash的AS代码来写一段实例,模仿设计软件中贝塞尔曲线的控制。

  下面是完成效果:



用鼠标点击拖动灰色的方形锚点,即可看见曲线的变化(小心不要拖出画面了)

  AS代码如下:

//这个函数是用来绘制线条的
function connect(){
this.clear()
this.lineStyle(3,0x660000,100)
this.moveTo(anchorOne._x,anchorOne._y)
this.curveTo(controlOne._x,controlOne._y,anchorTwo._x,anchorTwo._y)
updateAfterEvent()
}
//这个函数是用来绘制替代描点跟控制点的MC,就绘制一个正方形吧
function createSquare(handle,side,offset){
if(offset==undefines){
  offset=0
}
with(handle){
  moveTo(offset,offset)
  lineTo(offset,side)
  lineTo(side,side)
  lineTo(side,offset)
  lineTo(offset,offset)
  endFill()
}
}
//这是用来控制描点跟控制点的移动,并且用延时,间隔一段时间调用一次绘制线条
function setDraggable(handle){
handle.onPress=function(){
  clearInterval(_global.refreshScreen)
  _global.refreshScreen=setInterval(this._parent,"connect",10)
  this.startDrag(false)
}
handle.onRelease=function(){
  clearInterval(_global.refreshScreen)
  this.stopDrag()
}
handle.onReleaseOutside=function(){
  clearInterval(_global.refreshScreen)
  this.stopDrag()
}
}
//建立描点
anchorOne=createEmptyMovieClip("anchorPoint1",this.getNextHighestDepth())
anchorOne._x=anchorOne._y=50
//填充
anchorOne.beginFill(0xcccccc,100)
//样式
anchorOne.lineStyle(0,0x000000,100,false,false,"none","miter",2)
//调用函数绘制成正方形
createSquare(anchorOne,8,-8)
//调用后方可拖动
setDraggable(anchorOne)
//另一个描点
anchorTwo=createEmptyMovieClip("anchorPoint2",this.getNextHighestDepth())
anchorTwo._x=anchorTwo._y=250
anchorTwo.beginFill(0xcccccc,100)
anchorTwo.lineStyle(0,0x000000,100,false,false,"none","miter",2)
createSquare(anchorTwo,8,-8)
setDraggable(anchorTwo)
//控制点
controlOne=createEmptyMovieClip("control1",this.getNextHighestDepth())
controlOne._x=anchorTwo._x
controlOne._y=anchorOne._y
controlOne.beginFill(0xcccccc,100)
controlOne.lineStyle(0,0x000000,100,false,false,"none","miter",2)
createSquare(controlOne,8,-8)
setDraggable(controlOne)
//最后让线条一开始就显示出来
connect()

  复制粘贴到到吗层,测试即可看到效果。

上一页 [1] 下一页
评论人 评论内容摘要(共 0 条,查看完整内容) 得分 0 发表时间
 热点文章
·惊爆!《暗黑破坏神3》将对应全平台
·《荣誉勋章:太平洋之战》中文版上市
·MediaShow魅力四射快速制作音乐电子相册
·《花木兰》完美流程攻略
·轻松可爱 最新10大Q版网络游戏推荐
·2006年暑期新宣布免费网络游戏一览
·photoshop制作水晶球中的精灵
·NVIDIA发布Forceware 93.71 WHQL驱动
·经验分享 微软Word2007实用技巧两则
·国内新记录产生 1M super pi运算仅用9秒
 推荐文章
·微软高官爆料:欧盟对Vista哪些功能不安
·在Google Talk上与QQ、MSN好友聊天
·Word使用过程中的常见问题及其解决
·手把手教你内存终极变相“造假”大法
·NVIDIA联手海盗船 推出自动超频内存
·Windows Vista特殊功能介绍:语音识别
·公安机关检验软件样本 流氓软件制造者面临坐牢危..
·比英特尔UMPC还要小 移动PC新品推出
·性感暴力完美结合 御姐武戏X新画面
·盖茨访谈:我就是微软里的兼职员工
WinXP下载基地 版权所有 Copyright© 2006-2008 WWW.WinXpd.COM, All Rights Reserved. 页面维护: WinXP下载基地(WinXP基D)