Actionscript 3 如何使外部html文件中的链接在单击时在Actionscript中打开新框架?
我希望有人能帮助我解决我在动作脚本中的问题。我有一个外部html文件,其中有链接,当动态加载到flash中时,应该会打开新的窗口/框架。我已经设法完成了第一个链接,但其他两个链接我无法,由于函数linkhandler只处理一个链接。我如何使它处理所有链接,以便在单击每个链接时打开不同的框架。下面是我的代码和html文件Actionscript 3 如何使外部html文件中的链接在单击时在Actionscript中打开新框架?,actionscript-3,Actionscript 3,我希望有人能帮助我解决我在动作脚本中的问题。我有一个外部html文件,其中有链接,当动态加载到flash中时,应该会打开新的窗口/框架。我已经设法完成了第一个链接,但其他两个链接我无法,由于函数linkhandler只处理一个链接。我如何使它处理所有链接,以便在单击每个链接时打开不同的框架。下面是我的代码和html文件 import flash.display.Loader; import flash.net.URLLoader; import flash.net.URLRequest; imp
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
var myTextLoader:URLLoader = new URLLoader();
var myTextField_txt:TextField = new TextField();
var textStyle:TextFormat = new TextFormat();
var n:Array=new Array("Mythical Theories","Creation Theory","Evolution Theory");
textStyle.font = "Verdana";
textStyle.size = 14;
myTextField_txt.wordWrap=true;
myTextField_txt.autoSize=TextFieldAutoSize.LEFT;
myTextField_txt.multiline = true;
myTextField_txt.width = 480;
myTextField_txt.height = 300;
myTextField_txt.x = 10;
myTextField_txt.y = 80;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
var loadedText:URLLoader = URLLoader(e.target);
myTextField_txt.htmlText = loadedText.data
addChild(myTextField_txt);
myTextField_txt.setTextFormat(textStyle);
}
myTextLoader.load(new URLRequest("origin.txt"));
myTextField_txt.addEventListener(TextEvent.LINK, linkHandler);
function linkHandler(event:TextEvent):void {
// Open the link in a new window.
myTextField_txt.parent.removeChild(myTextField_txt);
myTextLoader.removeEventListener(Event.COMPLETE, onLoaded);
gotoAndStop(30);
}
Html文件
</p>- There are many theories that try to explain the origin of man.</p>
</p>- Most communities have stories that explain how human beings began to exist.</p>`enter code here`
</p>- We will look at three theories that try to explain the origin of man.</p>
</p><font color="#0000FF">1.<a href="event:TextEvent"><u>Mythical Theories</u></a></p>
</p>2.<a href="event:TextEvent"><u>Creation Theory</u></a></p>
</p>3.<a href="event:TextEvent"><u>Evolution Theory</u></a></p></font>
您可能应该为每个href使用不同的链接事件标签:
</p>- There are many theories that try to explain the origin of man.</p>
</p>- Most communities have stories that explain how human beings began to exist.</p>`enter code here`
</p>- We will look at three theories that try to explain the origin of man.</p>
</p><font color="#0000FF">1.<a href="event:Ref1"><u>Mythical Theories</u></a></p>
</p>2.<a href="event:Ref2"><u>Creation Theory</u></a></p>
</p>3.<a href="event:Ref3"><u>Evolution Theory</u></a></p></font>
未经测试,但应能正常工作
function linkHandler(event:TextEvent):void {
// Open the link in a new window.
myTextField_txt.parent.removeChild(myTextField_txt);
myTextLoader.removeEventListener(Event.COMPLETE, onLoaded);
var frameNum:uint;
switch (event.text) {
case "Ref1": frameNum = 10; break;
case "Ref2": frameNum = 20; break;
case "Ref3": frameNum = 30; break;
}
gotoAndStop(frameNum);
}