从xml文件获取href到flash按钮

时间:2012-11-03 00:52:12

标签: actionscript-3 flash-cs5

我有一个flash文件,我正在尝试根据单击的图像更改相同按钮的值,但我无法使其使用不同的值(我只能使其与静态值一起使用) )。

AS

var weblinkXML:XML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/main.xml");
weblinkXML.onLoad = function(success) {
    trace("success = "+success);
for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
PPTBUTTON.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_1);
        function fl_ClickToGoToWebPage_1(event:MouseEvent):void
        {
            navigateToURL(new URLRequest("test/test.html"), "_blank");
        }
    }
}

我的XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<content>
    <!-- general vars -->
    <settings>
        <item name="copyright"><![CDATA[<font letterspacing="0.5">© 2012 | <a href="event:privacy,0">PRIVACY POLICY</a></font>]]></item>
        <item name="companyName"><![CDATA[<font letterspacing="-2"><b>TANITA</b></font>]]></item>
        <item name="companySlogan"><![CDATA[<font letterspacing="1">PHOTO PORTFOLIO</font>]]></item>
        <!--mp3Url srcUrl="music.mp3"/-->
        <imagesPage>
            <image imageUrl="images/tfile_splash_pic_main.jpg" />
        </imagesPage>
    </settings>

    <!-- menu -->
        <menu>
            <button><![CDATA[PORTFOLIO]]></button>  
            <button><![CDATA[ABOUT]]></button>  
            <button><![CDATA[NEWS]]></button>   
            <button><![CDATA[CONTACTS]]></button>   
        </menu>

        <gallery gallName="Crystal Cabin Awards 2012">
            <image imageUrl="gallery/tfile_gall_small_01.jpg" imagesBig="gallery/tfile_gall_big_01.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.google.com"/>
        <image imageUrl="gallery/tfile_gall_small_02.jpg" imagesBig="gallery/tfile_gall_big_02.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.youtube.com"/>
        <image imageUrl="gallery/tfile_gall_small_03.jpg" imagesBig="gallery/tfile_gall_big_03.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.yahoo.com"/>
            <image imageUrl="gallery/tfile_gall_small_04.jpg" imagesBig="gallery/tfile_gall_big_04.jpg"/>
            <image imageUrl="gallery/tfile_gall_small_05.jpg" imagesBig="gallery/tfile_gall_big_05.jpg"/>
            <image imageUrl="gallery/tfile_gall_small_06.jpg" imagesBig="gallery/tfile_gall_big_06.jpg"/>
            <image imageUrl="gallery/tfile_gall_small_07.jpg" imagesBig="gallery/tfile_gall_big_07.jpg"/>
            <image imageUrl="gallery/tfile_gall_small_08.jpg" imagesBig="gallery/tfile_gall_big_08.jpg"/>
        </gallery>

我意识到我的xml很复杂,但它正在整个闪存中使用。也许我可以将它简化为一个独立的xml,就像:

<image imageUrl="gallery/tfile_gall_small_02.jpg" imagesBig="gallery/tfile_gall_big_02.jpg" buttonName="PPTBUTTON" targ="_self" href="http://www.youtube.com"/>

我的问题是我试图将href变成一个变量并使用它而不是“test / test.html”但它永远不会起作用。

我也意识到我在for中有一个方法但是在这一点上我已经对这段代码进行了如此多的迭代,我不确定如何继续。

1 个答案:

答案 0 :(得分:0)

以下是我将如何检索href属性列表:

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xml/main.xml");
loader.addEventListener(IOErrorEvent.IO_ERROR, function errorHandler(event:IOErrorEvent):void {
    trace("Error loading XML" + event.type);
});
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
    trace("success = " + event);
    var xml:XML = new XML(loader.data);
    var xmllist:XMLList = xml.gallery.children();
    for (var i:Number = 0; i < xmllist.length(); i++) {
        trace(XML(xmllist[i]).attribute("href"));
    }
});
loader.load(request);

我有以下输出:

success = [Event type="complete" bubbles=false cancelable=false eventPhase=2]
http://www.google.com
http://www.youtube.com
http://www.yahoo.com

我希望有所帮助。