我正在做一个在地图上显示大头针的小程序。有关引脚的信息来自XML文件,包括价格。当一个价格按钮被点击时,假设是900美元,只有带有900的引脚需要放大。所有的引脚都存储在一个pinContainer_mc中(放置所有引脚的空白容器)
有扩展方法的Pin异端pin类。
package bin
{
import flash.display.MovieClip;
public class pin extends MovieClip
{
var thisHeight:int;
var thisWidth:int;
public function pin()
{
thisHeight = this.height;
thisWidth = this.width;
}
public function enlarge():void
{
this.height = thisHeight *2;
this.width = thisWidth *2;
}
public function regular():void
{
this.height = thisHeight;
this.width = thisWidth;
}
}
}Main FLA具有以下内容:
// Parsing and displaying pins
for(var i:int = 0; i< myXmlList.length(); i++)
{
pin_mc = new mcPin();
pinContainer_mc.addChild(pin_mc);
pin_mc.x = myXml.Community[i].xAxis;
pin_mc.y = myXml.Community[i].yAxis;
pin_mc.name = myXml.Community[i].Name;
pin_mc.price = myXml.Community[i].Price;
}单击按钮时:
rangeA_mc.addEventListener(MouseEvent.CLICK, enlargePins);
function enlargePins(e:MouseEvent):void
{
for(var i:int =0; i<pinConatiner_mc.numChildren;i++)
{
if(pinContainer_mc.getChildAt(i).price == 900)
{
pinContainer_mc.getChildAt(i).enlarge();
}
}
}它给出编译错误:Access of possibly undefined property price through a reference with static type flash.display:DisplayObject。
发布于 2010-11-06 01:50:55
getChildAt返回一个没有DisplayObject属性的价格。
如果您确定已添加到pinContainer_mc的所有子对象(看起来确实如此),则可以将返回值强制转换为pin以解决此问题。
将您的代码更改为:
if(pin(pinContainer_mc.getChildAt(i)).price == 900)https://stackoverflow.com/questions/4108536
复制相似问题