实战Fireworks MX插件开发指南
(二) 为OK按钮添加相应的程序代码。
1、先制作一个标准的OK按钮,并将其插入主场景。
2、转到主场景,选取OK按钮,打开Action面板,并转到Expert Mode(专家模式)。由于我们需要在按下OK按钮时,执行我们的程序,因此为此按钮添加以下脚本:
on (release) {
}
3、首先在最开始加入我们的变量定义,代码如下:
// 用户输入变量.
var Width = Number(_root.ButW);
var Height = Number(_root.ButH);
var Left = Number(_root.ButL);
var Top = Number(_root.ButT);
var Round = Number(_root.ButR/100);
var BColor = (_root.ButC);
var Right = Left+Width;
var Bottom = Top+Height;
//第二个矩形的参数
var SWidth = Width*0.9;
var SHeight = Height*0.5;
var SLeft = Left+(Width/20);
var STop = Top+(Height/20);
var SRound = Round*1.6;
var SRight = SLeft+SWidth;
var SBottom = STop+SHeight;
4、下面我们需要将Fireworks API调用加入此函数。在Flash MX中,每个API函数都可以被Flash API所调用,它们之间是通过以下方法互相传递的,即使用MMExecute()函数。例如在Fireworks中的以下命令:
fw.getDocumentDOM().addNewRectanglePrimitive({left:Left, top:Top, right:Right, bottom:Bottom}, Roundess);
调入Flash MX中后需要转换为:
MMExecute("fw.getDocumentDOM().addNewRectanglePrimitive({left:"+left+", top:"+top+", right:"+right+", bottom:"+bottom+"},"+Round+");");
需要注意的是,MMExecute取代了以前旧版本的FWJavascript函数,不过FWJavascript仍旧可以使用,也就是说以下写法同样可以执行:
FWJavascript("fw.getDocumentDOM().addNewRectanglePrimitive({left:"+left+", top:"+top+", right:"+right+", bottom:"+bottom+"},"+Round+"); ");
不过我们推荐使用新的第一种写法。此时加入的脚本如下所示:
//绘制第一个矩形
MMExecute ("fw.getDocumentDOM().addNewRectanglePrimitive({left:"+left+",
top:"+top+", right:"+right+", bottom:"+bottom+"},"+Round+");
");
//填充第一个矩形渐变色
MMExecute ("fw.getDocumentDOM().setFill({
category:'fc_Linear', ditherColors:[ '#000000', '#000000' ], edgeType:'antialiased',
feather:0, gradient:{ name:'cn_Custom', nodes:[ { color:'#ffffff',
isOpacityNode:false, position:0 }, { color:'"+BColor+"',
isOpacityNode:false, position:1 } ], opacityNodes:[ { color:'#000000',
isOpacityNode:true, position:0 }, { color:'#000000', isOpacityNode:true,
position:1 } ] }, name:'Linear Smooth', pattern:null, shape:'linear',
stampingMode:'blend opaque', textureBlend:0, webDitherTransparent:false
});");
//设置第一个矩形渐变色方向
MMExecute ("fw.getDocumentDOM().setFillVector({x:"+Left+",y:"+Bottom+"},
{x:"+Left+", y:"+Top+"}, {x:"+Right+",
y:"+Bottom+"});");
//添加Inner Shadow效果
MMExecute ("fw.getDocumentDOM().applyEffects({
category:'UNUSED', effects:[ { EffectIsVisible:true, EffectMoaID:\"{5600f702-774c-11d3-baad0000861f4d01}\",
ShadowAngle:315, ShadowBlur:5, ShadowColor:'#000000a6', ShadowDistance:0,
ShadowType:0, category:'Shadow and Glow', name:'Inner Shadow' }
], name:'UNUSED' });");
//绘制第二个矩形
MMExecute ("fw.getDocumentDOM().addNewRectanglePrimitive({left:"+SLeft+",
top:"+STop+", right:"+SRight+", bottom:"+SBottom+"},"+SRound+");
");
//填充第二个矩形
MMExecute ("fw.getDocumentDOM().setFill({
category:'fc_Linear', ditherColors:[ '#000000', '#000000' ], edgeType:'antialiased',
feather:0, gradient:{ name:'cn_Custom', nodes:[ { color:'#000000',
isOpacityNode:false, position:0 }, { color:'#ffffff', isOpacityNode:false,
position:1 } ], opacityNodes:[ { color:'#000000', isOpacityNode:true,
position:0 }, { color:'#000000', isOpacityNode:true, position:1
} ] }, name:'Linear Smooth', pattern:null, shape:'linear', stampingMode:'blend
opaque', textureBlend:0, webDitherTransparent:false });");
//改变第二个矩形的填充方向
MMExecute("fw.getDocumentDOM().setFillVector({x:"+SLeft+",y:"+SBottom+"},
{x:"+SLeft+", y:"+STop+"}, {x:"+SRight+",
y:"+SBottom+"});");
//改变混合模式
MMExecute ("fw.getDocumentDOM().setBlendMode('screen');");
5、OK按钮的执行脚本基本已经输完了,最后我们还需要添加一个结束此命令的语句,以便释放相应的变量并返回到用户的当前文档。Flash MX提供了新的MMEndCommand()函数,以取代旧版本的FWEndCommand()函数,当然FWEndCommand()仍旧得到支持。脚本代码如下:
// End command and release system resources
MMEndCommand (true, "");
(三) 为Cancel按钮添加相应的脚本。相对来说Cancel的脚本就很简单了,只需结束当前命令并返回到用户文档即可,代码如下:
on (release) {
// End command and release system resources
MMEndCommand (true, "");
}
