2009-11-21 128 views
0

我試圖創建一個手風琴菜單關閉一個在線教程。我遵循Original Tutorial的每一步(我認爲),但根據我的大小更改了內容,並且使實例名稱相應地以_mc或_txt結尾。但由於某種原因,它似乎沒有工作。手風琴菜單錯誤1010


我得到#1010錯誤,它並沒有真正弄清楚什麼:

TypeError: Error #1010: A term is undefined and has no properties.
at tutorial _ fla::MainTimeline/placeItemsOnStage()
at tutorial _ fla::MainTimeline/onComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()


我有了所有的圖像插入,我的第一個XML文件一個沒有改變應該工作正常。

我知道這是很長,但我希望有人可以檢查出來進不去。我對此非常陌生,幾乎不得不放棄整個項目。非常感謝!

我的代碼:

//import tweenlite classes 
import gs.TweenLite; 
import gs.easing.*; 

var MENU_ARRAY:Array; //used to save the items data 
var OPENED_MENU:int; //to inform the menu that should be open at startup 
var MOVE_ON_MOUSE_OVER:Boolean=false; //tha name says everything 
var xmlLoader:URLLoader; //the xml loader 

loadXML("menu2.xml"); //load the xml 

function loadXML(Uri:String):void { 
    xmlLoader = new URLLoader(); 
    xmlLoader.addEventListener(Event.COMPLETE, onComplete); 
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError); 
    xmlLoader.load(new URLRequest(Uri)); 
} 

function onError(evt:ErrorEvent):void { 
    trace("cannot load xml file"); 
} 

function onComplete(evt:Event):void { 
    //read and load xml into array, by parsing it using prepareMenu 
    MENU_ARRAY=prepareMenu(xmlLoader.data.toString()); 
    placeItemsOnStage(); //place all required items on stage. 
} 

function placeItemsOnStage():void { 
var pos:Number=0; 
    //define the container properties 
    menuContainer_mc.x=0; 
    menuContainer_mc.y=0; 

for(var c:int=0; c<MENU_ARRAY.length; c++) { 
    var it:menuItem = new menuItem; //load out menuItem, because its exported to AS, we can use it here 
    it.x=c*51; //its the gray border width 
    it.y=0; //place on top 
    it.id="Item-"+c; //id the menuItem 
    it.name="Item-"+c; //name de menuItem 
    it.posX=pos; //actual pos, useful to open and know is position 
    it.itemLabel_txt.text=String(MENU_ARRAY[c].Ititle).toUpperCase(); //load the label in uppercase 
    it.addEventListener(MouseEvent.CLICK, onMouseClick); //add mouse click listener 
    if(MOVE_ON_MOUSE_OVER==true) it.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); //if configured, load the mouse over event 
    it.useHandCursor=true; //use hand cursor 
    it.buttonMode=true; //buttonMode 
    it.itemText_txt.visible=false; //hide the textField 
    menuContainer_mc.addChild(it); //add the menu item as child 

    if(String(MENU_ARRAY[c].IcontentType)=="image/swf") { //check the content and load things accordint to it 
     var ldr:Loader = new Loader(); 
     ldr.x=51; 
     ldr.y=0; 
     it.addChild(ldr); 
     ldr.load(new URLRequest(MENU_ARRAY[c].IcontentData.toString())); 
    } 
    else if(String(MENU_ARRAY[c].IcontentType)=="text") { 
     it.itemText_txt.visible=true; 
     it.itemText_txt.text=MENU_ARRAY[c].IcontentData.toString(); 
    } 
pos+=51; //the next menuItem x position 
} 

//put mask in place 
masker_mc.width=(MENU_ARRAY.length*51+700) 
masker_mc.height=menuContainer_mc.height; 
masker_mc.x=0; 
masker_mc.y=0; 

moveItem(OPENED_MENU-1); //open menu confirured in XML 

} 

function onMouseOver(evt:MouseEvent):void { 
if(evt.target.name.toString()=="buttonBack") prepareMove(evt) 
} 

function prepareMove(evt:MouseEvent):void { 
    var targetName:String = evt.currentTarget.name.toString(); //get the menuItem 
    var temp:Array = targetName.split("-"); //split his name: Item-x 
    var itemNumber:int=(temp[1]); //got item number 
    moveItem(itemNumber); //move it 
} 

function onMouseClick(evt:MouseEvent):void { 
    if(evt.target.name.toString()=="buttonBack") prepareMove(evt); //mouse action was done in buttonBack 
    else trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area 
} 

function moveItem(num:int):void { 
    var itemToMove:menuItem=menuContainer_mc.getChildByName("Item-"+String(num)) as menuItem; 
    //get the menuItem child 
    for(var m=0;m<MENU_ARRAY.length;m++) //move one-by-one to the new position 
    { 
    var tempMc = menuContainer_mc.getChildByName("Item-"+m); 
    if(tempMc.x > itemToMove.x) TweenLite.to(tempMc, 1, {x:((tempMc.posX) + itemToMove.width-51), ease:Quart.easeOut}); //see tweenLite for info about this. 
    else if(tempMc.x <= itemToMove.x) TweenLite.to(tempMc, 1, {x:(tempMc.posX), ease:Quart.easeOut}); 
    } 
} 

function prepareMenu (XMLData:String):Array 
    { 
    //make sure it cames in XML 
    var menuXML:XML = new XML(XMLData); 
    //just in case 
    menuXML.ignoreWhitespace = true; 

    //get XML item's entrys 
var XMLItems = menuXML.descendants("item"); 

    //load all items into an array 
    var itemsArray:Array = new Array(); 
    var itemObj:Object; 
    for(var i in XMLItems) 
    { 
    itemObj=new Object(); 
    itemObj.Ititle=XMLItems[i][email protected]; 
    itemObj.IcontentType=XMLItems[i][email protected]; 
    itemObj.IcontentData=XMLItems[i][email protected]; 
    itemObj.itemID="menu"+i; 
    itemsArray.push(itemObj); 
    } 
    [email protected]; //get menu for open. 
    MOVE_ON_MOUSE_OVER=([email protected]()=="true" ? true : false); //get the option for load or not mouseOver open 
    return itemsArray; 
} 

//finish. 
stop(); 

回答

0

「術語」指的標識符,「錯誤#1010:一個術語是不確定的,沒有屬性」是指使用的是不能被求值的表達式。當您嘗試通過其字符串名稱訪問和使用未定義的對象屬性時,通常會發生這種情況,如myobject["property"].method()。你能提供引發異常的確切行嗎?

+0

非常感謝你! 它沒有給我它的線。它在錯誤控制檯中說的就是我在代碼上面發佈的內容。如果你雙擊它,它實際上不會把你帶到AS – May 2009-11-21 16:36:28

+0

你能在Flash的調試器中運行代碼嗎?只需在placeItemsOnStage()的第一行設置一個斷點,遍歷該函數並查看崩潰的位置。 – Simon 2009-11-22 10:00:39