我正在創建一個Flash影片,用於加載一些包含某些文本和圖像URL的細節的XML,該影片需要替換Flash影片中現有的MovieClip。用閃存中的新顯示對象替換顯示對象
有沒有在Flash中替換現有MovieClip或更新它的方法,以便更新的/新的顯示對象保持原始顯示對象的原始外觀,並且原始顯示對象的任何補間仍然有效我們新建或更新的顯示對象。
感謝
斯蒂芬
更新:這裏是我用來加載此代碼:
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Loader;
import flash.text.TextField;
import flash.events.ProgressEvent;
// get the number of children in display list
var count:uint = numChildren;
// get the url for the Ceres server
//var configUrl:String = loaderInfo.parameters.configUrl;
// load the config file from the server using the configUrl
var configUrl:String = "C:\development\projects\ReadXMLInFlash\example_xml_ceres_response.xml"; //loaderInfo.parameters.configFileUrl;
var defaultImgUrl:String = loaderInfo.parameters.defaultImgUrl;
var urlRequest:URLRequest = new URLRequest(configUrl);
// create the XML loader
var urlLoader:URLLoader = new URLLoader();
urlLoader.load(urlRequest);
urlLoader.addEventListener(Event.COMPLETE, onDataLoaded);
//Error handling ;
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
//Could be an error or just a message;
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
function onDataLoaded(evt:Event):void
{
var myXML:XML = new XML(evt.target.data);
var node:XML;
// loop through the XML
for each (node in myXML.dynamicGroups.DynamicGroup.assets.Asset.elements.Element)
{
// check the assetValue of the XML, if contains http then a link use 'createNewImageLoader'
if(String(node.assetTagName) == 'Image')
{
createNewImageLoader(node.assetValue, node.elementName);
}
else
{
// else it is text (e.g. a product descrition) use createNewTextLoader
createNewTextLoader(node.assetValue, node.elementName);
}
}
}
//error callbacks
function onIOError(evt:IOErrorEvent)
{
trace("IOError: "+evt.text);
// if an error load the default image
var defaultImgLoader:Loader = new Loader();
var defaultImgUrl:URLRequest = new URLRequest(defaultImgUrl);
defaultImgLoader.load(defaultImgUrl);
addChild(defaultImgLoader);
}
function onHTTPStatus(evt:HTTPStatusEvent)
{
//trace("HTTPStatus: "+evt.status);
}
function onSecurityError(evt:SecurityErrorEvent)
{
trace("SecurityError: "+evt.text);
}
// loads a image asset
function createNewImageLoader(loadURL:String, elementname:String):void
{
for(var i:uint=0;i<numChildren;i++)
{
var display:DisplayObject = getChildAt(i);
if (elementname == display.name)
{
var loader:Loader = new Loader();
var urlRequest:URLRequest = new URLRequest(loadURL);
loader.addEventListener(Event.COMPLETE, function(){
loader.x = display.x;
loader.y = display.y;
addChild(loader);
removeChild(display);
});
loader.load(urlRequest);
}
}
}
// adds new text to a display object
function createNewTextLoader(textToLoad:String, elementname:String):void
{
trace("elementname:" + elementname);
for(var i:uint=0;i<count;i++)
{
var display:DisplayObject = getChildAt(i);
trace("displayName:" + display.name);
if (elementname == display.name)
{
var textToDisplay:TextField = new TextField();
textToDisplay.text = textToLoad;
textToDisplay.x = display.x;
textToDisplay.y = display.y;
addChild(textToDisplay);
removeChild(display);
break;
}
}
}
你是什麼意思「更新/新的顯示對象保持原始顯示對象的原始外觀「? – Kodiak 2011-12-15 10:22:33