在Flash CS3中制作Fla形式的组件
2007-12-26 11:18:30 来源:WEB开发网6、点中库中的"MyButton"元件,右键菜单中选"Component Definition"(组件定义)选项,会进入一窗口,把类名填上"MyButton",再把"diaplay in Components panel"选项打上钩,"Tool tiptext"中填入组件名称,我这里填"MyButton".这里还有设置组件的preview(预览)效果还有图标等,其他内容大家可根据需要自行设置。
7、到这步,我们会发现还缺少一个外部的自定义组件的代码,也就是上面"MyButton"元件连接的"MyButton"类.由于类中导入了组件类,所以我们要设置FLASH CS3的classPath(类路径),选编辑-->参数设置-->ActionScript-->ActionScript3.0,添加一新的类搜索路径,我这里为"D:Program FilesAdobeAdobe Flash CS3enConfigurationComponent SourceActionScript 3.0User Interface"
大家根据各自情况设置好路径,新建ActionScript文档,填入如下代码:
/************MyButton.as**************/
package{
importflash.display.*;
importflash.events.*;
importflash.system.ApplicationDomain;
importfl.core.UIComponent;
publicclassMyButtonextendsUIComponent{
privatevarnowSkin:MovieClip;
privatevarthisDomain:ApplicationDomain;
publicfunctionMyButton(){
super();
trace("MyButton");
}
overrideprotectedfunctiondraw():void{
if(nowSkin==null){
thisDomain=loaderInfo.applicationDomain;
varclassDef
try{
classDef=thisDomain.getDefinition(getNormalSkinName());}
catch(e:ReferenceError){
trace("没有在库中找到相关的类!")
return;
}
nowSkin=newclassDefasMovieClip;
nowSkin.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
addChild(nowSkin);
}
nowSkin.width=width;
nowSkin.height=height;
}
protectedfunctionmouseOverHandler(e:MouseEvent):void{
trace("over");
removeChild(nowSkin);
varclassDef=thisDomain.getDefinition(getOverSkinName());
nowSkin=newclassDefasMovieClip;
addChild(nowSkin);
nowSkin.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
draw();
}
protectedfunctionmouseOutHandler(e:MouseEvent):void{
trace("out");
removeChild(nowSkin);
varclassDef=thisDomain.getDefinition(getNormalSkinName());
nowSkin=newclassDefasMovieClip;
addChild(nowSkin);
nowSkin.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
draw();
}
protectedfunctiongetNormalSkinName():String{
return"NormalSkin";
}
protectedfunctiongetOverSkinName():String{
return"OverSkin";
}
}
}
更多精彩
赞助商链接