调用的方法Embed可能未定义

来源:互联网 发布:翻页电子相册制作软件 编辑:程序博客网 时间:2024/06/05 02:51

这个问题好奇怪,一般来说,调用的方法或属性未定义,基本上都是因为某个对象没有被初始化。

 

 

出问题的代码如下:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
     <![CDATA[
        import mx.events.ListEvent;
       
        [Bindable]
        private var dp:Array = [
                                {name:"John Smith", position: "developer"},{name:"Ellen Smith", position: "manager"},
                                {name:"Hames Smith", position: "accountant"},{name:"Jane Smith", position: "designer"}
                                ]                  //解决方法:后面加个分号;就可以了,百思不得其解!
                               
        [Embed(source="image/1.jpg")]
        public var managerIcon:Class;
       
        [Embed(source="image/2.jpg")]
        private var designerIcon:Class;
       
        [Embed(source="image/3.jpg")]
        private var accountantIcon:Class;
       
        [Embed(source="image/4.jpg")]
        private var developerIcon:Class;                        

        private function setIcon(value:*):Class
        {
            if(value.position != null)
            {
                switch(value.position)
                {
                    case "manager":
                        return managerIcon;
                        break;
                    case "developer":   
                        return developerIcon;
                        break;
                    case "accountant":   
                        return accountantIcon;
                        break;
                    case "designer":   
                        return designerIcon;
                        break;
                }
            }
            return null;
        }
    ]]>
</mx:Script>
<mx:Canvas width="400" height="300" backgroundColor="0x00ffff">
    <!--<mx:Button click="setEditor()"/>-->
    <mx:List x="50" y="30" width="200" selectedIndex="1" id="listImpl" selectionColor="0xccccff" labelField="name"
         dataProvider="{dp}" editable="true" verticalScrollPolicy="on" iconFunction="setIcon"/>
</mx:Canvas>
</mx:Application>

原创粉丝点击