×

Flash中加载HTML文件

Kalet Kalet 发表于2009-08-11 09:04:41 浏览189 评论0

抢沙发发表评论

关键字: 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;

//System.useCodePage = 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即可。

群贤毕至

访客