Flash中加載HTML文件

1、建立三個圖層,從上至下分別爲action(控制代碼)、text(加載內容)、bg(背景圖);

2、選中bg圖層第一幀,插入一關鍵幀,導入一圖片做背景;

3、選中text圖層第一幀,插入一關鍵幀,添加一動態文本框,設置好其屬性,並將其實例命名爲content_txt;

4、選中action圖層第一幀,加入以下代碼:

var myStyle:TextField.StyleSheet = new TextField.StyleSheet();
myStyle.load("sample.css");
content_txt.styleSheet = myStyle;

content_txt.multiline= true;
content_txt.wordWrap = true;
content_txt.html = true;

var story:XML = new XML();
story.ignoreWhite = true;
story.load("sample.html");
story.onLoad = function () {
content_txt.htmlText = story;
}

5、建sample.html文件:

<body>
<headline>Giant Sea Lion Spotted</headline>
<subheadline>Citizens scared, amazed</subheadline>

<biline>Today - Our City </biline><mainBody>A giant sea lion was spotted today rampaging around the city's main square, scaring thousands of innocent people just out for a daily stroll in the beautiful downtown district.
<img align='right' src='sample.jpg'/>No injuries were reported after the animal's two-hour assault of the shopping district famous for it's sea lion purses and shoes, also known as the "sea lion district". Witnesses said the creature came out of the ocean near the Burger King at 42nd and 1st Avenue, startling many and stalling traffic.
"The animal caused nearly four million dollars of damage to the neighborhood," said Joseph Valente, owner of "Sea Lions R' Us" at 43rd and 2nd. Onlookers to the scene said that the sea lion appeared ornery, but otherwise in good spirits.
Officials are uncertain as to when, if ever, the sea lion may return.<A HREF="http://www.macromedia.com">Click here for more.</A> </mainBody>
</body>

和sample.css文件


headline {
font-family: Arial,Helvetica,sans-serif;
font-size: 16px;
font-weight: bold;
display: block;
}
subheadline {
font-family: Arial,Helvetica,sans-serif;
font-size: 13px;
font-weight: bold;
display: block;
}
mainBody {
font-family: Arial,Helvetica,sans-serif;
font-size: 10px;
display: block;
}
biline {
font-family: Arial,Helvetica,sans-serif;
font-size: 11px;
font-style: italic;
display: inline;
}
A {
font-family: Arial,Helvetica,sans-serif;
color:cccccc;
font-size: 10px;
display: inline;
text-decoration:underline;
}

將以上兩個文件和導出的SWF文件放同一目錄下。

注意:在sample.html文件中用到一圖片,隨便找幅將其命名爲sample.jpg即可。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章