views:

258

answers:

1

Hey guys,

I'm trying to create an accordion menu off of an online tutorial. I followed every step (i think) on Original Tutorial but changed things according to my size, as well as make the instance names end with _mc or _txt accordingly. But for some reason it doesn't seem to be working.


I'm getting the #1010 error and it doesn't really clarify anything:

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()


I have my first xml file that has all the images to insert and that one hasn't been changed at all should work fine.

I know this is long, but I'm hoping someone can check it out anyhow. I'm extremely new to this and would pretty much have to abandon the whole project. Thanks so much!

my code:

//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].@Ititle;
    itemObj.IcontentType=XMLItems[i].@IcontentType;
    itemObj.IcontentData=XMLItems[i].@IcontentData;
    itemObj.itemID="menu"+i;
    itemsArray.push(itemObj);
  }
  OPENED_MENU=menuXML.@menuOpen; //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();
A: 

"term" refers to an identifier, "Error #1010: A term is undefined and has no properties" means you are using an expression which cannot be evaluated. This usually happens when you try to access and use an undefined object property via its string name as in myobject["property"].method(). Can you provide the exact line on which the exception is raised?

Simon
thank you so much!it doesn't give me the line it's on. All it says in the error console is what I posted above the code. if you double click on it, it doesn't actually take you to the AS
May
Can you run the code in Flash's debugger? Just set a breakpoint on the first line of placeItemsOnStage(), step through the function and see where it crashes.
Simon