ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:101.63KB ,
资源ID:6292239      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6292239.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(通过Flash+JavaScript+API来解析fla文件.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

通过Flash+JavaScript+API来解析fla文件.docx

1、通过Flash+JavaScript+API来解析fla文件通过Flash+JavaScript+API来解析fla文件1 引言在flash教学中,有时需要对学生的媒体创作做一些量化的统计,以检验学生的学习程度。在这个过程中,需要设定一磐知识点(比如对Flash作品中淡入淡出效果的检测),然后学生根据这些知识点完成对作品的创作并提交。对于学生提交上来的大量作品(fla文件),检验手段成了一个困难的问题。如果依靠教师的手工批阅,这将是一件十分繁重的任务,所以自动分析fla文件成了一个非常迫切的要求。虽然Macromedia公司不提供fla文件格式说明,但提供Flash JavaScript AP

2、l支持,使得可以从另外一个角度去分析fla文件。2 Flash JavaScript API根据nash提供的帮助文档,可以知道:Flash JavascriptAPI即nash Javascript应用程序编程接口,是一个辅助编程工具。该工具可用来创建在创作环境中运行的脚本。同时,作为扩展Flash的主要部分,Flash JavaScript API提供了在Fash创作环境中(即用户保持Flash程序打开期间)执行多个动作的脚本的功能,这有助于简化创作过程。这意味着,既可以利用其来创作E1够h动画,也可以利用其来读取fla文件中各种对的属性。3 Flash文档对象模型(DOM)要做到这一点,

3、还需要了解一下Flash文档对象模型fDOM)因为n聃h JavaScript API基于文档对象模型(DOM),该模型允许使用JavaScript对象访问Flash文档(即fla文档)。在nash帮助文档中,提供了对于DOM结构包括各个对象的方法和属性的详细描述。但根据实际情况,一般只需了解其中主要的对象和属性。图l中描述了对有用的简化的Flash文档对象模型。用于flash JavaScript AFI的flash文档对象模型(DOM)包含一组顶级函数和两个顶级对象(FLfile对象和Flash对象()。一切就从这两个顶级对象开始。(1)启动flash8,选择新建“Flash JavaSc

4、ript文件”命令,在编辑器中输入以下代码:var strlis:new Array();定义(字符串)数组var timeLines=new Array();f1openDocument(file:C:checkfIa:打开被检文件vardoc:flgetDocumentDOM0;得到文档对象模型接口 timeLines=doctimelines;得到Flash时间轴(场景)。 。;trIiSDush(docheight); 得到文档宽度、高度、背景色、帧率、,场景数,并追加到strlis数组中strlispush(docwidth);strlispush(docbackgroundColo

5、r);strlispush(docframeRate);strlispush(timeLines.length);FLfile write(file:C:fltest tXtstrtis);,将strlis数组的值写入 /fltest.txt/关闭被检文件 closeDocument(file:lC:lcheck-fla,false);,天即傲伍x阡(2)将文件保存,如“testjsfl”。将待检测的fla文件复制到c盘,并命名为”check.fla“的一些文件属性的截图。(3)双击“testjsfl”文件运行。这时会自动肩动Fish(如果Flash没有肩动)并执行jsn中Flash Java

6、Script代码,将结果写人“c:LOtest ixt”文件。(4)打开fltesttxt,观察得到的执行结果(各属性值以“,”分隔)如图3所示。通过上面的例子,可以初步了解Rash JavaScript运行机制以及如何输出结果至外部文件。5外部程序调用Flash JavaScript(jsfl)在实际应用中需要南自己的应用程序去调用FlashJavaScfipt代码。不过需要指出的是,外部应用程序必须通过Flash来达到这个目的(机器上必须安装有ndMx及以上完整版)。实现此目的的方法很简单,即可以利用sheExecute函数。以Delphi为例,调用代码如下:ShellExecute lA

7、pplication Handle,open,flashexe,c:testjs矿nmSWSHOW);综上所述应用原理如图4所示6应用举例(解析fIa文件)61(Delphi70)应用程序界面和运行结果如图5所示在主表单L置人一个Button和一个TreeView控什。在这个应用中利用jsn得到解析结果。为了方便观察和下一步自动批阅功能最终解析结果在TreeView控件中以树状结构显示。该应Jj完整地呈现了如何读取fla文件中的主要对象属性值的过程和方法。62外部应用程序代码usesShellAPI;引用函数ShellExecute所需单元procedure TForml ButconlCli

8、ck(Sender:TObject);#ButtonlIl点击事件VarfList:TStringList;b:beolean;procedure split(var tarlist:TStringlist;s:string;c:widechar);,i亥子过程根据特殊字符分割字符串(在本应用中,以”字符分,膈字符串)vari:integer;tempstr:string;se:widestring;begintempstr:=”:tarlist Clear;if s“thenbeginse:=widestring(s);for i:=1 to length(sel dobeginif sei

9、=c thenbegintarlistAdd(tempstr);tempstr:=“:endelsetempstr:=tempstr+seli;end;tarlist Add(tempstr);end;end;split子过程结束beginButtonlClick主程序解析伯文件井以树形结构显示|舟析结果b:=true;fList:=TStnngListCreate;DeleteFile(c:fTree txt):DeleteFile(c:fltest txt 7):ShellExecute(Handleopen,flash exec:fltest jsfl,州,SW_SHOW):while

10、b do 等待flash exe执行js制完毕并释放txt控制,ArvfListLoadFromFile(c坩Iteattxtl; ,导人结果文件(txt)b:=false;exceDtcontinue; end;split(fListUtf8ToAnsi(fListStrings0),):以“,”为分隔符分蒯字符串。形成一棵树 fListSaveToFile(c:fTreetxt,)TreeViewlLoadFromFile(c:fTreetxt,)fListFree;end;63 jsfl文件中的Flash JavaScript代码该代码显示了对fla文档中各个主要对象(如场景、图层、关键

11、帧、实例、元件等)及其属性的读取方法。为了更好地观察代码。简化了对fla文档中对象属性的读取,即减少了同一个对象的属性读取代码行,一般读取2个属性。更多的属性可以参看Flash中的帮助文件。源代码如下:var Level=0;模拟栈指针var strlis=new Array();定义(字符串)数组Mar str=new String();f1openDocument(。file:C:checkfla。):getTabStr(i)胳到前缀符Tab串,用来构建树的/层次var S=。:while(i0)s+= 。:tab键i-:return S:lfunction strlisPush(i,S)

12、替换字符串中的某些特殊符号并追加到strlis数组中str=String(s);str=strreplace(Arg”):str=strreplace(Ang,);str=strreplace(g”):去掉“,”str=strreplace(9,“:去掉Tab符str=strreptace(、s)I舾$)g,“)去掉首尾空格strlispush(getTabStr(i)+str);lvar doc=f1getDocumentDOM0;文档对象模型tl=new 朋寸间轴对象数组var lib=doc1ibrary; flash元件库对象var itemArray=new Array(); 元件对

13、象数组var layerGroup=new Array(); 图层对象数组var frameGroup=new Array(); 帧对象数组var elementGroup-new Array();元素数组var fillitem=new Array(); ,填充对象数组var strokeltem=new Array(); II笔触对象数组var filterGroup=new Array(); 滤镜对象数组var timeLines=new Array(); ,H寸间轴对象数组itemArray=libitems;timeLines=doctimelines;i=O:j-0:t=0:str

14、lisPush(LeveI,doc。):Level+;str|isPush(LeveI,height):st r|isPush(LeveI+1,docheight);str|isPush(LeveI,width。):strlisPush(LeveI+1,docwidth);st rIisPush(LeveI,。backgroundCoIor。):stisPush(LeveI+1,docbackgroundCoIor);st rIisPush(Level,frameRate。):strlisPush(LeveI+1。docframeRate);st r|isPush(LeveI,sceneCou

15、nt。):st r|isPush(Level+1timeLines1ength);function getArray(xarray)var s=“;var k=0:fork=O;kxarray1ength;k+)s=s+xarray【k】+:。re“jm S:function pushFill(Levelfillitem)填充对象属性读取函数strlisPush(Level+l,。color);strIisPushILeveI+2,fillitemcolor);strIisPushILeveI+1。style。):strIisPushLeveI+2fillitemstyIe):,更多属性略,下

16、同function pushStroke(Level,strokeltem)笔触对象属性,厂读取函数st rIisPushILeveI+1,。color。:st rlisPushLevel+2,strokeltemcolor);strlisPush(LeveI+1,。style。):st rIisPush(LeveI+2,strokeltemstyle);|一function pushElementFS(Level,k,singleElement)元素的肭氧充和笔触属性读取函数docseIectNone):t1currentFrame=k;singleElementselected=true;

17、docselection0=singleElement;st rIisPushLeveI+1,。fi):fillitem=docgetCustomFill(。selection。):DushF川lLeveI+1,fillitem);st r|isPushLevel+1,。stroke”):strokeltem=docgetCustomStroke(selection。):pushStroke(Level+1,strokeltem);function pushFilter(Level,filterltem),滤镜对象属性读取函数str|isPushILeveIfilterltemname);st

18、r|IsPushLeveI+1。name。):s订IisPush(LeveI+2filterltemname);str|isPush(LeveI+1。angle。):strlisPush(Level+2Mathround(filterltemangle);、function pushElement(flagLevelsingleElementk)元素,属性读取函数var s=“:s=singleElementelementType;jf IsingleElementelementType=。text。)文本s=s+。【_+singleElementgetTetStrlng()+。】-:)if

19、IsingleElementelementType=。instance。)元件实例,s=s+。l_+singleElement1ibraryltemname+。】。:)st rIisPushLeveIs):stisPush(LeveI+1,。name。):strlisPush(Level+2singleElementname);strlisPush(Level+l,。elementType。):strlisPush(Level+2,singleElementelementType);if(singleElementelementType=。shape。)形状fstr|isPush(LeveI+

20、1,。isGroup):str|isPush(LeveI+2,singleElementisGroup);strlisPush(Level+1,isDrawingObject。):strIisPush(LeveI+2singleElementisDrawingObject);if(flag)形状如果存在于元件库中的元件的图层,中,需要进入剪辑元件模式获得填充、笔触等值libeditltem(itemArrayiname);pushElementFS(LevelksingleElement);docexitEditMode;)LeVelelsepushElementFS(Levet,k,sing

21、leElement);1pushFilter(Level,if(singleElementelementType=strlisPush(Level+1,。textTystrIisPush(Level+2singleElementtextType);strIIsPush(LeveI+1,。TextString。):strlisPush(Level+2singleElementgetTextStrin90);if(singleElementtextType=。static。)str|isPushLevei+1。orientation。):strIisPush(LeveI+2,singleEleme

22、ntorientation);if IsingleElementtextType=。dynamic singleElementtextType=。input。)strIisPushLeveI+1,。embeddedCharacters。):strIisPushLeveI+2,singleElementembeddedCharacters);str|isPush(LeveI+1,embedRanges。):strIisPush(LeveI+2,singleElementembedRanges);|)strlisPush(Level+l,。face。):strlisPush(LeveI+2,sin

23、gleElementgetTextAttr(。face。):strlisPush(Level+1,。size。):strlisPush(Level+2。singleElementgetTextAttr(。size。)l:if(singleElementelementType=。instance。)str|isPushLevel+1,。instanceType。):strlisPushLeveI+2,singleElementinstanceType):strlisPush(Level+l,。libraryltemName。);strlisPush(Level+2,singleElement1i

24、braryltemname):ifsingleElementinstanceType=。symbol。)str|isPush(Level+1,。symbolType。):strIisPushLeveI+2,singleElementsymbolType):strIisPushLevel+1,。actionScript。):strIisPush(Level+2,singleElementactionScript);filterGroup=singleElementfilters;if(filterGroup!=undefined)+:strlisPush(Level,filters。):for

25、Ik=O:kfiIterGroup1ength;k+)(LeVef+:,filterGroupk);。text。)Level一一;e。):Level一一:function pushFrames(flag,k,Level,singleFrames)关键帧腑象属性读取函数 var-0:st rIisPush(LeveI,k+1):st rIisPush(LeveI+1,。name。):strlisPush(Level+2,singleFramesname);strltsPush(Levej+1,soundName):strlisPush(Level+2singleFramessoundName);

26、|if(singleFramestweenType!=none。)腑h间类型strlisPush(Level+1。motionTweenOrientToPath):st州sPushLeveI+2,singleFramesmotionTweenOrientToPath);strIisPush(LeveI+1”motionTweenRotate):strIisPush(LeveI+2,singleFramesmotionTweenRotate);l|I)elementGroup=singleFrameselements;st rIisPush(LeveI+1,。elementCount):st r

27、IisPush(Level+2elementGroup1ength);Level+;strlisPush(Level,elementGroup。):while I(eIementGroup1ength)&i=1 0),避免多元素检测导致程序变慢Level+;pushElement(flagLevel,elementGroupi,k):Level一一:i+:function pushLayer(flagLevel,singleLayer)图层对象属性读取函数var k=0:strlisPush(Level,singleLayername);st rIisPush(Level+1,。layerTy

28、pe。);strlisPush(Level+2singleLayer1ayerType);strIisPush(Level+1,。color。):strIisPushLevel+2,singleLayercolod;frameGroup=singleLayerframes;Level+;strlisPush(Level,frameSeries。):while(kframeGroup1ength)Level+;pushFrames(flag,k,Level,frameGroupk);k=k+frameGroupkduration;Level-;ll主程序,获取场景strlisPush(Level

29、,scenes):for(t=0;ttimeLines1ength;t+Level+;tl=timeLinest;deceditScene(t)strlisPush(Level,t1name);Level+;strlisPush(Level,frameCount);strIisPushLevel+1,t1frameCount);strlisPushlLeveI,layerCount。):strlisPush(Level+l,t11ayerCount);layerGroup=t11ayers;strlisPush(Level,layers):for(j=0;jt11ayerCount;j+)Level+;pushLayer(false,L

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1