Pay for Hesitation: 1037: Packages cannot be nested

Pages

2008年3月17日 星期一

1037: Packages cannot be nested

這個問題常常出現在flex newbie想把.as匯進Flex或Flash時發生..
(我之前就發生過, 不知怎麼解決, 就又把原本拆開的as及mxml還原在一起..白做工)

昨天又嘗試了一次, 總算找到問題所在..

To include ActionScript code, you reference an external ActionScript file in your tags. At compile time, the compiler copies the entire contents of the file into your MXML application, as if you had actually typed it. As with ActionScript in an block, ActionScript in included files can only consist of variable declarations if outside functions. Included files can also declare constants and namespaces, include other ActionScript files, import declarations, and use namespaces. You cannot define classes in included files.

Variables and functions defined in an included ActionScript file are available to any component in the MXML file. An included ActionScript file is not the same as an imported ActionScript class. Flex provides access to the included file’s variables and functions, but does not add a new class, because the MXML file itself is a class.

所以意思是, 你的MXML在被Flex解譯時,會還原成class。
而include .as做的動作就像marco是直接展開。

所以要include actionscript檔,
如:<ms:Script source="a.as"/>
在a.as中就不能用package{} 及 class{}包覆。
(會形成class包覆class!!)

也就是說mxml不能import as的class, 只能用include的方式將外部的as載入展開。

而import這個指令似乎也只能用在"as class" import another "as class".

官方說明:Comparing, including, and importing ActionScript code


1 則留言:

Odd 提到...

我記得可以用import的@@,
只要將package是在src下的資料夾,
在CDATA中用import foldername.classname;是可以的 @@
然後在actionscript中只要使用classname就可以用了!@@