I am trying to ascertain which sub array from the main array received a click event. My approach below makes use of a switch case at the end for this purpose;
However I keep getting a type error in the output tab that says:Code:var localSegment:Array = [segment1.system_Cab, segment1.programs_Cab, segment1.userFiles_Cab, segment1.rollback_Cab] var external_MediaSegment:Array = [segment2.externalHD_Cab, segment2.virtualDisk_Cab] var network_LocationSegment:Array = [segment3.homeServer_Cab, segment3.wifiFlashdrive_Cab, segment3.encrivaPlay_Cab] var superVolumes:Array = [localSegment, external_MediaSegment, network_LocationSegment] for (var i:Number = 0; i < superVolumes.length; i++ ){ for (var j:Number = 0; j< superVolumes[i].length; j++){ var fmCabinent = superVolumes[i][j]; fmCabinent.addEventListener(MouseEvent.CLICK, openCabinet); } } var arrayContainer:Array; //create a var to reference the clicked item's parent array var curIndex:int; //a temporary variable to store the index of clicked object var targetCabinent; function openCabinet (e:MouseEvent):void{ targetCabinent = e.currentTarget; for (var i:Number = 0; i < superVolumes.length; i++ ){ curIndex = superVolumes[i].indexOf(e.currentTarget); //see if the sub array contains the clicked item if(curIndex > -1){ //if the sub array contains the clicked item (e.currentTarget) arrayContainer = superVolumes[i][curIndex]; break; //stop looping since you found the array } if (targetCabinent.currentFrame == 1){ targetCabinent.play(); }else { fmCabinent.addEventListener(Event.ENTER_FRAME, closeCabinet); } switch(arrayContainer){ case localSegment: trace("You clicked an item from local segment"); break; case external_MediaSegment: trace("YOu clicked something from media segment"); break; case network_LocationSegment: trace("You clicked something from network_LocationSegment"); break; } } } //stage.addEventListener (MouseEvent.CLICK, outFocusClose); function closeCabinet (e:Event):void{ if (targetCabinent.currentFrame > 1){ targetCabinent.prevFrame(); }else{ fmCabinent.removeEventListener(Event.ENTER_FRAME, closeCabinet); //stage.removeEventListener (MouseEvent.CLICK, outFocusClose); } }
TypeError: Error #1034: Type Coercion failed: cannot convert Phoenix_Assetbuilder_fla::Systemfilescabinet_17@5d 1b5661 to Array.




Reply With Quote
