Flex 编译CSS文件的错误:Invalid Embed directive in stylesheet

今天试图重新改变现有的CSS Framework,放弃之前自定义的CSSLoader,采用运行时加载CSS的方式。

不过目前还是做尝试,需分析两种方式所能处理的各种情况,找出需要处理的特殊情况,然后分析是否值得更改。

采用运行时加载CSS的方式

需将CSS文件预编译成SWF文件,看了网上提供的方式,发现直接在Flex Builder中compile,找不到生成的SWF文件。。也不是很了解其中的机制,于是采用另外一种方式,切换到Flex Builder的安装目录,找到SDK下的bin目录mxmlc.exe,执行,输入命令mxmlc path/test.css,然后在path下会生成相应的test.swf。

不过在编译的时候出现错误:

Invalid Embed directive in stylesheet - can't resolve source 'Embed("/assets/test.png")'

搜索了半天发现中文只有少量帖子关于这个问题,但是并没有解决方案,于是切换搜英文的,果然发现很多相关帖子,简而言之根本原因就是Embed中提供的路径有问题,编译时无法根据给出的路径找到相应的文件。

下面贴出解决方案以及一些有用的回复,我就懒得翻译了,反正大部分人都能看懂英文:

写道
Invalid Embed directive in stylesheet

Onafewoccasionsnow,fornoreallyapparentreason,suddenlyourProblemPanewillbespammedwithtonsofmessagesallsortoflookinglikethis:

InvalidEmbeddirectiveinstylesheet-can'tresolvesource'Embed(source="/assets/common.swf",symbol="AccordionHeader_disabledOverSkin")'.

Inthepast,sometimesitwouldonlyhappenonamac,othertimeswindowsmachines.I'vetrieddeletingmybinfolder,cleaningtheproject,recompilingtheswf's,movingtheswf'saround,changingthesyntaxinthecsseversoslightly.I'vegoogledthisonmanyoccasionsandfoundnoclearanswer.TodayIdecidedthatIneededtoknowwhatcausedthisandifinfactIfigureditout,toshareitwithyou.

Whatendedupbeingtherootcauseofourproblemisthatinseveralplacesintheapplicationwewerereferencingimageassetsdirectlyinourassetsfolder,i.e./assets/delete.png,whichisoftenthecasewhenourdesignersaren'tkeepingupwithassetcreationanddevelopersjustthrowsomeimageupasaplaceholderforthetimebeing.NowitjustsohappenedthatONEofthesereferenceswasincorrectanditsEmbedpointedtoafilethatdidnotexist.IdiscoveredthiswhenIcommentedoutourstylecssreferencesintheapplication,andsawtheerroronlythen.Itwasthisbrokenreferencethatcausedtheaboveerror.Ifixedthereferencetopointtotherightfile,didaProjectclean,andalltheInvalidEmbedDirectiveerrorswentaway.

Ishouldnotethatwehadover100referencestosymbolsinourcss,andbydefaultFlexbuilderonlyshowsthefirst100errors.Unluckilythe"unabletoresolve'assets/deleted.png'fortranscodingin...."waserrornumber138anddidnotshowupinthelist.Ihadtochangemypreferencestoshowall138errors.

Sothelessonlearnedisthatwhenyougetspammedwiththiserror,itcouldwellbethatonlyoneEmbedtagsomewhereinyourappisactuallybroken,andthatyourcssandswfisprobablyjustfine.

符合我的情况的回复:

写道
Just thought I'd add that I've run into this error in the past specifically when compiling with the command line compiler or with flex ant tasks. I was experiencing an issue where FB's built in compiler would compile without errors, but the command line/ant compilers would return with the "Invalid Embed" errors. It turned out that for some reason the command/ant compilers were having difficulty resoloving abosolute paths such as '/assets/images/myImage.png'. I was able to resolve the errors by changing the absolute path references to relative path references such as '../../../assets/images/myImage.png' in files that were reporting errors.

相关推荐