FLEX3类不能嵌套的问题解决方法

    技术2022-05-19  18

            本人最近学习FLEX,开发环境用的MYECLIPSE8.5+FLEX BUILDER3插件,在开发的过程中遇到了个奇怪的问题,写的MXML文件明明没有错误,可是eclipse报错说类不能嵌套,这个时候如果切换到设计视图,发现又没错误了,如果切换回源码视图,又开始报错,报错的时候就无法编译,导致程序无法编译运行,后来看了网上部分文章说是FLEX版本的问题,于是,我就删掉了FLEX3插件,下了个FLXE BUILDER4插件, 安装后发现还是存在些问题,老提示某个文件找不到,具体文件名忘了,后来分析了下,在设计视图下不报错,说明代码没问题,于是,我就重新恢复到FLEX3插件,然后将FLEX SDK换成了刚才安装的FLEX4附带的SDK3.5,发现不报错了,以为问题解决了,没想到过了一会又出现了这个问题,我就试着点了下myeclipse的project菜单下的clean,再编译就没问题了,看来还是编译器有些问题。

           由此看来,MYECLIPSE8.5搭配FLEX SDK3有些问题,当代码绝对正确可编译不过去的时候就该思考是不是环境或者JAR包出了问题,就该清理下编译环境和运行环境,以前采用SSH框架开发的项目中也遇到过类似的问题,在编译过程中,老提示类找不到,可是含有指定类的包明明就在LIB目录下,后来发现是lib目录里含有同一个包的2个版本,于是去掉了较老的版本,问题就解决了,其实想想原理也是很好理解的,编译器在编译的时候发现了2个路径一模一样的类,这个时候编译器不知道调用哪个类无法继续编译也就是情理之中的事情了。

     

           本人在学习《FLEX权威指南》的过程中,发现其中有个assets文件夹,书中并没有提及到这个文件夹的位置,我在学习过程中,自己摸索着在项目的src文件下补上assets这个文件夹,路径就没问题了。

     

           这里贴上书中第5课的完整代码,供以后参考:

    <?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="prodHandler(groceryInventory)"><mx:Model id="groceryInventory" source="assets/inventy.xml"/><mx:Script> <![CDATA[  private function prodHandler(theItems:Object):void{   trace(theItems.prodName);      trace(theItems.cost);  } ]]></mx:Script><!-- <mx:Model id="groceryInventory"> <groceries> <catName>Diary</catName> <prodName>Milk</prodName> <imageName>assets/logo.jpg</imageName> <cost>1.20</cost> <listPrice>1.99</listPrice> <isOrganic>true</isOrganic> <isLowFat>true</isLowFat> <description>direct from califounia where cows are happiest!</description> </groceries></mx:Model>--> <mx:states>  <mx:State name="cartView">   <mx:SetProperty target="{products}" name="width" value="0"/>   <mx:SetProperty target="{products}" name="height" value="0"/>   <mx:SetProperty target="{cartBox}" name="width" value="100%"/>   <mx:AddChild relativeTo="{cartBox}" position="lastChild">    <mx:DataGrid id="dgCart" width="100%">     <mx:columns>      <mx:DataGridColumn headerText="Column 1" dataField="col1"/>      <mx:DataGridColumn headerText="Column 2" dataField="col2"/>      <mx:DataGridColumn headerText="Column 3" dataField="col3"/>     </mx:columns>    </mx:DataGrid>   </mx:AddChild>   <mx:RemoveChild target="{linkbutton1}"/>   <mx:AddChild relativeTo="{cartBox}" position="lastChild">    <mx:LinkButton label="Continue Shopping" click="this.currentState=''"/>   </mx:AddChild>    </mx:State>  <mx:State name="expanded">  <mx:AddChild>   <mx:VBox x="200" width="100%">    <mx:Text text="{groceryInventory.description}" width="50%"/>    <mx:Label text="Certified Orginic"/>    <mx:Label text="Low Fat"/>   </mx:VBox>  </mx:AddChild>  </mx:State> </mx:states> <mx:ApplicationControlBar x="0" y="10" width="100%" height="90" dock="true">  <mx:Canvas width="100%" height="100%">   <mx:Label x="0" y="0" text="flex"/>   <mx:Label x="0" y="41" text="GROCER"/>   <mx:Button y="25" label="View Cart" id="btnViewCart" right="90"/>   <mx:Button y="25" label="Checkout" id="btnCheckout" right="10"/>  </mx:Canvas> </mx:ApplicationControlBar> <mx:Label text="(c)2006,FlexGrocer" right="10" bottom="10"/> <mx:HBox x="0" y="0" width="100%" height="100%" id="bodyBox">  <mx:VBox width="100%" height="100%" id="products">   <mx:Label text="Milk" id="prodName"/>   <mx:Image id="image1" source="@Embed('assets/logo.jpg')" scaleContent="true" mouseOver="this.currentState='expanded'" mouseOut="this.currentState=''"/>   <mx:Label text="$1.99" id="price"/>   <mx:Button label="Add to Cart" id="add"/>     </mx:VBox>  <mx:VBox height="100%" id="cartBox">   <mx:Label text="Your Card Total:$"/>   <mx:LinkButton label="View Cart" click="this.currentState='cartView'" id="linkbutton1"/>   </mx:VBox> </mx:HBox></mx:Application>


    最新回复(0)