我在Flash CS5/AS3項目中有一個內容滾動條,我想在多個位置使用這些項目,同時在這些不同位置的每個位置加載不同的內容(html)。Flash AS3編碼變量對每次調用的初始化方式不同
下面是滾動文本組件的AS3代碼。 'compnentsettings.xml'是我定義要調用什麼.html文件的地方。
現在我只有一個地方的滾輪工作。我可以克隆它,但當然,它會加載相同的數據。
我相信我有修改從scrolledTextComponent.as(下圖)settingsComponent函數加載不同compnentSettings.xml文件
我需要的變量初始化__xmlSettingsPath每次調用不同的,我不知道該怎麼辦這個。請幫忙!
package com
{
import flash.display.*;
import flash.events.TimerEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.text.StyleSheet;
import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.events.*;
import com.LoadXmlPlayerClass;
public class scrolledTextComponent extends MovieClip
{
// component variables
private var __xmlSettingsPath:String = "componetsettings.xml";
private var _sheet:StyleSheet = new StyleSheet();
public var _loadSettingsXml:LoadXmlPlayerClass = new LoadXmlPlayerClass();
private var _settingsXmlTimmer:Timer = new Timer(250);
public var _loadXml:LoadXmlPlayerClass = new LoadXmlPlayerClass();
private var _newsTimmer:Timer = new Timer(250);
//private var _loaderIcon_mc:LoaderMC = new LoaderMC(); //used to show xml loading state
private var _urlCSS:URLRequest = new URLRequest();
private var _loaderCSS = new URLLoader();
private var _urlHTML:URLRequest = new URLRequest();
private var _loaderHTML = new URLLoader();
//text
private var _txt:TextField = new TextField();
private var _MyScrollBar:MyScrollBar = new MyScrollBar();
public function scrolledTextComponent()
{
loaderIcon_mc.visible=true;
readSettingsXml();
}
/* Other Functions */
private function readSettingsXml() :void
{
if(__xmlSettingsPath != '')
{
//loaderIcon_mc.visible=false;
//read XML file
_loadSettingsXml.loadFile(__xmlSettingsPath);
_settingsXmlTimmer.addEventListener(TimerEvent.TIMER,settingsComponent);
_settingsXmlTimmer.start();
}
}
//timmer
private function settingsComponent(event:TimerEvent):void {
//_settingsXmlTimmer.stop();
//trace ("initial is running: "+_settingsXmlTimmer.running);
if (_loadSettingsXml.isxmlread && _settingsXmlTimmer.running) {
_settingsXmlTimmer.stop();
//trace ("after is running: "+_settingsXmlTimmer.running);
loaderIcon_mc.visible=true;
loaderIcon_mc.x=(_loadSettingsXml._myXml.record[0].scrollComponentWidth-loaderIcon_mc.width)/2;
loaderIcon_mc.y=(_loadSettingsXml._myXml.record[0].scrollComponentHeight-loaderIcon_mc.height)/2;
_txt.width = _loadSettingsXml._myXml.record[0].scrollComponentWidth-40;
_txt.height = _loadSettingsXml._myXml.record[0].scrollComponentHeight;
_txt.mouseWheelEnabled=true;
_txt.multiline = true;
_txt.wordWrap = true;
_txt.selectable = true;
_txt.condenseWhite=true;
_txt.border=false;
_txt.x=0;
_txt.y=0;
if (_loadSettingsXml._myXml.record[0].cssStylesPath!='') {
_urlCSS=new URLRequest(_loadSettingsXml._myXml.record[0].cssStylesPath);
_loaderCSS.addEventListener(Event.COMPLETE, onCSSFileLoaded);
_loaderCSS.load(_urlCSS);
}
}
}
private function readHTML() :void
{
if (_loadSettingsXml._myXml.record[0].htmlPath!='') {
_urlHTML=new URLRequest(_loadSettingsXml._myXml.record[0].htmlPath);
_loaderHTML.addEventListener(Event.COMPLETE, onHTMLFileLoaded);
_loaderHTML.load(_urlHTML);
}
}
private function addHTMLandScroll() :void
{
addChild(_txt);
if (_txt.height<_txt.textHeight) {
_MyScrollBar.x=_txt.x+_txt.width+20;
_MyScrollBar.y=_txt.y+14;
_MyScrollBar._height=_txt.height-28;
_MyScrollBar._txt=_txt;
_MyScrollBar.scrollable_area_mc.height=_txt.height-28;
_MyScrollBar.scrollDownButton.y=_txt.height-14;
_MyScrollBar.initPublicVars();
addChild(_MyScrollBar);
}
}
private function onCSSFileLoaded(event:Event):void {
_sheet.parseCSS(_loaderCSS.data);
//_timer_txt.styleSheet = sheet;
_txt.styleSheet = _sheet;
readHTML();
}
private function onHTMLFileLoaded(event:Event):void {
_txt.htmlText = _loaderHTML.data;
loaderIcon_mc.visible=false;
addHTMLandScroll();
}
}
}
有關如何解決這個問題的任何建議?我有點新在這..
感謝您的回覆。我理解第一部分,但是我將如何/將在哪裏將第二,第三,第四部分稱爲.. scrolledtextcompnents? – AlxSTi 2010-12-11 16:31:07
看看編輯。 – loxxy 2010-12-12 03:12:39