下面这段代码测试的时候,报空指针错误,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:v="views.ecomm.*"
xmlns:m="managers.*">
<mx:Script source="as/ecomm.as"/>
<mx:states>
<mx:State name="cartView">
<mx:SetProperty target="{prodTile}" name="width" value="0"/>
<mx:SetProperty target="{prodTile}" name="height" value="0"/>
<mx:SetProperty target="{cartBox}" name="width" value="100%"/>
<mx:AddChild relativeTo="{cartBox}" position="lastChild">
<v:Cart id="shoppingCart"
width="100%"
cart="{cart}"
productRemoved="deleteProd(event.product)"/>
</mx:AddChild>
<mx:AddChild relativeTo="{cartBox}" position="lastChild">
<mx:LinkButton label="Continue Shopping" click="this.currentState=''"/>
</mx:AddChild>
<mx:RemoveChild target="{linkbutton1}"/>
<mx:RemoveChild target="{cartView}"/>
</mx:State>
</mx:states>
<mx:ApplicationControlBar dock="true" width="100%" height="90">
<mx:Canvas width="100%" height="100%"
horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Label x="0" y="0" text="Flex" click="ecommNav.selectedChild=homePage"/>
<mx:Label x="0" y="41" text="GROCER" click="ecommNav.selectedChild=homePage"/>
<v:CategoryView id="catView"
width="600"
left="100"
cats="{categories}"
categorySelect="displayProdByCategory(event)"/>
<mx:Button label="View Cart" id="btnViewCart" right="90" y="0" click="showCart()"/>
<mx:Button label="Checkout" id="btnCheckout" right="10" y="0" click="ecommNav.selectedChild=checkout"/>
</mx:Canvas>
</mx:ApplicationControlBar>
<mx:ViewStack id="ecommNav" width="100%" height="100%">
<v:HomePage id="homePage"/>
<mx:HBox x="0" y="0" width="100%" height="100%" id="bodyBox">
<v:FoodList id="prodTile"
width="100%" height="100%"
prodByCategory="{prodByCategory}"
itemAdded="addToCart(event.product)"/>
<mx:VBox height="100%" id="cartBox">
<mx:HBox>
<mx:Label text="Your Cart Total: $"/>
<mx:Label text="{cart.total}"/>
</mx:HBox>
<mx:LinkButton label="View Cart" id="linkbutton1"/>
<mx:List id="cartView"
dataProvider="{cart.aItems}"
width="100%"
dragEnter="doDragEnter(event,'cartFormat')"
dragDrop="doDragDrop(event,'cartFormat')"/>
</mx:VBox>
</mx:HBox>
<v:Checkout id="checkout" width="100%" height="100%"/>
</mx:ViewStack>
<mx:Label text="(c) 2006, FlexGrocer" bottom="10" right="10"/>
<m:CategorizedProductManager id="catProds"
catDataLoaded="categorizedProductDataLoaded()" />
</mx:Application>
其中,问题发生在这里:<mx:RemoveChild target="{linkbutton1}"/>
<mx:RemoveChild target="{cartView}"/> 这两个目标组件如下:
<mx:LinkButton label="View Cart" id="linkbutton1"/>
<mx:List id="cartView"
dataProvider="{cart.aItems}"
width="100%"
dragEnter="doDragEnter(event,'cartFormat')"
dragDrop="doDragDrop(event,'cartFormat')"/>
我把这两个目标组件的相关依赖都删除后,只保留id属性或者label属性。结果还是报空指针错误,这是怎么回事啊?无解中。。。跪求大虾帮忙,小弟感激不尽!!
不知道算不算诡异的空指针错误,不说废话了,请看代码
最新推荐文章于 2024-03-11 18:09:55 发布