我对AS3非常陌生,似乎在我的头上。
我正在尝试让脚本拉出一个不同的.xml文件,这取决于从前一个场景中的数组生成菜单中选择的内容。虽然我希望它更灵活,但我愿意创建一个'if'语句来选择.xml - 但是我无法跟踪将根据所选菜单项改变的变量。
这是我目前正在使用的内容。这是灵活的版本(我仍然有希望)。就像我说的那样,我对此非常陌生,如果你需要了解更多以获得更好的图片,请告诉我。
var item_list = new Array();
var i:Number;
var total:Number;
var find_xml:XML = new XML();
// This part is what pulls from the frame that this is placed on
// The as3 script on the frame --- "page_2.load_xml("enter xml file");"
function push_array(e:Event):void{
find_xml = XML(e.target.data);
total = find_xml.item.length();
for( i = 0; i < total; i++ ){
item_list.push( { content: find_xml.item[i].content.toString() } );
}
}
function load_xml(xml_file:String):void{
var xml_loader:URLLoader = new URLLoader();
xml_loader.load( new URLRequest( xml_file ) );
xml_loader.addEventListener(Event.COMPLETE, push_array);
}
//Here is where the variable holding the .xml will go
var xml_file:String = place variable with .xml file name here;
感谢您的帮助!
---- ADDED:这是剩下的代码----
try{
var key_str:String;
var value_str:String;
var param_obj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for ( key_str in param_obj ){
value_str = String( param_obj[key_str] );
if( key_str == "xml_file" )
xml_file = value_str;
break;
}
}
catch (error:Error) {}
touch_slider.load_gallery( xml_file );
import flash.net.URLRequest;
import flash.ui.ContextMenu;
var menu:ContextMenu = new ContextMenu();
var copyright:ContextMenuItem = new ContextMenuItem( "" );
var credit:ContextMenuItem = new ContextMenuItem( "" );\
menu.hideBuiltInItems();
menu.customItems.push(copyright, credit);
this.contextMenu = menu;
function visit(e:Event){
var my_link:URLRequest = new URLRequest( "" );
navigateToURL( link, "_self" );
}
function visit_bar_slider(e:Event){
var my_link:URLRequest = new URLRequest( "" );
navigateToURL( my_link, "_parent" );
}
答案 0 :(得分:0)
编辑你的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<photos>
<config auto_play="true" auto_play_duration="5" slide_direction="left" tween_duration="0.5" tween_effect="easeInOutQuad"/>
<photo>
<filename>photos/ninki.jpg</filename>
<target>_self</target>
</photo>
<photo>
<filename>photos/richmond_station.jpg</filename>
<target>_self</target>
</photo>
</photos>
并使用此函数将它们拉入数组
var photolinks:Array = new Array();
var phototargets:Array = new Array();
function pullXMLtoArray(xml:XML):void
{
var auto_play = xml.config.@auto_play; //a sample for pulling settings
var photolist:XMLList = xml.photo;
var photo:XML;
for each (photo in photolist)
{
photolinks.push(String(photo.filename));
phototargets.push(String(photo.target));
}
}
所以,现在,你有2个不同的数组,一个用于photolinks,另一个用于phototargets ......
photolinks [1]&amp; phototargets [1]属于同一个照片节点