gpt4 book ai didi

css - 将外部 css 应用于加载到 flash ActionScript 中的 xml

转载 作者:行者123 更新时间:2023-11-28 14:17:13 25 4
gpt4 key购买 nike

我需要将 styled xml 渲染到 flash 游戏中。这是我尝试过的方法,但 css 样式不起作用:

这是我的样式表woorden.css:

.f {color:red;}

这是我的 xml woorden.xml:

<?xml version="1.0" encoding="utf-8"?>
<woorden>
<spel>
<goed>boordevol</goed>
<fout>boordenvol</fout>
<fbk><![CDATA[Het is dus ber<span class="f">e</span>goed, boordevol, reuzeleuk en apetrots, maar berenvel en reuzenlaars.]]></fbk>
</spel>
</woorden>

这是我目前的actionscript:

package {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.Event;
import flash.xml.*;
import flash.text.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.ui.Mouse;

public class BO_tussen_n extends MovieClip {
internal var woorden:XML;
internal var spelAr:Array;
internal var sheet:StyleSheet;
internal var myLoader:URLLoader;

public function BO_tussen_n () {
//constructor
var ld:myLd = new myLd();
ld.x = 20;
ld.y = 160;
ld.name = "ld";
addChild (ld);

load_xml ();
}
internal function load_xml () {
var myLoader:URLLoader = new URLLoader();
var itemNumber:uint = 0;

myLoader.load (new URLRequest("woorden.xml"));
myLoader.addEventListener (Event.COMPLETE, handleMyData);

function handleMyData (event:Event):void {
woorden = new XML(event.target.data);
woorden.ignoreWhite = true;
myLoader = null;
load_css ();
}

}
internal function load_css () {
myLoader = new URLLoader();
sheet = new StyleSheet();

myLoader.load (new URLRequest("woorden.css"));
myLoader.addEventListener(Event.COMPLETE, load_game);
}

internal function load_game (event:Event) {
trace(myLoader.data);
sheet.parseCSS(myLoader.data);
removeChild (getChildByName("ld"));
add_text ();
}
internal function add_text () {
var myFont:Font = new myFt();
var myFmt:TextFormat = new TextFormat();
myFmt.font = myFont.fontName;
myFmt.align = "center";
myFmt.leading = 1.2;
myFmt.size = 14;
myFmt.bold = true;

var myText:TextField = new TextField();
myText.defaultTextFormat = myFmt;
myText.x = 5;
myText.y = 5;
myText.width = 500;
myText.height = 100;
myText.autoSize = "left";
myText.textColor = 0x000000;
myText.multiline = true;
myText.wordWrap = true;
myText.styleSheet = sheet;
myText.htmlText = woorden.spel[0].fbk;
myText.name = "topTekst";

addChild (myText);
}
}

编辑:为了实验,我在我的样式表中添加了一个 h1 样式,并且 Flash 确实正确地呈现了它。所以这可能与 span-tag 或类有关?

最佳答案

在样式表中,我将 .f {color:red} 替换为 .f {color:#ff0000;} 从那以后我就再也没有遇到过问题。

关于css - 将外部 css 应用于加载到 flash ActionScript 中的 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8939186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com