-
Flash Genie
swf files from xml and looping
Hi,
loading swf from xml and button click is done, only looping the swf animation is missing, if someone can help in loop the code check below code
Code:
function nextClipLOAD(event:Event):void {
if(_swfToAdd.currentFrame == _swfToAdd.totalFrames)
{
index++;
_swfToAdd = _swfClipsArr[index];
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
==============================
stop();
/*
=======================================
NOTE: ALL SWF FILES must b AS3 exported
http://www.beautifycode.com/the-fine...e-swfs#snippet
=======================================
*/
import flash.events.*;
import flash.display.*;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
var i:uint;
var myXML:XML = new XML();
var XML_URL:String = "banner.xml";
var indexSWF = 0;
var frames:Number;
var _swfLoader:Loader;
var _swfRequest:URLRequest;
var _swfClipsArr:Array = new Array();
var _swfTempClip:MovieClip;
var _loadedSWFs:int;
var _swfToAdd:MovieClip;
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
var index = 0;
/*
=============
METHOD - I
=============
*/
//call link in XML Banner tag
//Converting XML LIST into XML Array
var bannerList:XMLList = myXML.banner.link;
var BannerArray:Array = new Array();
for each (var tempXML:XML in bannerList)
{
BannerArray.push(tempXML);
}
/*
=============
METHOD - II
=============
*/
//var BannerArray:Array = new Array("00.swf", "01.swf", "02.swf");
/*
=============
METHOD - III
=============
*/
/* var arrayLoader:Loader = new Loader;
var thisMovieClip:MovieClip;
var frames:Number
var swf_URL:String = "rbd_fastsaver.swf";
var swfURL:URLRequest = new URLRequest(swf_URL);
arrayLoader.load(swfURL)*/
/*
=============
*/
startLoading(BannerArray);
function startLoading(pathArr:Array):void {
_swfLoader = new Loader();
_swfRequest = new URLRequest();
loadSWF(pathArr[0]);
//trace (loadSWF(pathArr[0])); //rbd_generic.swf
}
function loadSWF(path:String):void {
//checking contentLoaderInfo
setupListeners(_swfLoader.contentLoaderInfo);
_swfRequest.url = path;
//trace(_swfRequest.url);//*.swf
_swfLoader.load(_swfRequest);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
}
function currentSwfProgress(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
// swfPreloader.percentTF.text = _perc + "%";
}
//
function onSwfComplete(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
_swfTempClip = event.target.content;
_swfTempClip.customID = _loadedSWFs;
//trace("ID: " + _swfTempClip.customID);
_swfClipsArr.push(_swfTempClip);
//trace(_loadedSWFs);
if(_loadedSWFs <BannerArray.length - 1) {
_loadedSWFs++;
loadSWF(BannerArray[_loadedSWFs]);
trace(BannerArray[_loadedSWFs]);
} else {
_swfLoader.unloadAndStop();
_swfLoader = null;
onCompletePreloading();
}
}
function onCompletePreloading():void {
_swfToAdd = _swfClipsArr[0];
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
textf.addEventListener(Event.ENTER_FRAME, frameNumberText);
stage.addEventListener(Event.ENTER_FRAME, nextClipLOAD);
banner_btn1.addEventListener(MouseEvent.CLICK, setContent);
banner_btn2.addEventListener(MouseEvent.CLICK, setContent);
banner_btn3.addEventListener(MouseEvent.CLICK, setContent);
banner_btn4.addEventListener(MouseEvent.CLICK, setContent);
banner_btn5.addEventListener(MouseEvent.CLICK, setContent);
banner_btn6.addEventListener(MouseEvent.CLICK, setContent);
}
function setContent(event:MouseEvent):void {
switch(event.target.name) {
case "banner_btn1":
_swfToAdd = _swfClipsArr[0];
break;
case "banner_btn2":
_swfToAdd = _swfClipsArr[1];
break;
case "banner_btn3":
_swfToAdd = _swfClipsArr[2];
break;
case "banner_btn4":
_swfToAdd = _swfClipsArr[3];
break;
case "banner_btn5":
_swfToAdd = _swfClipsArr[4];
break;
case "banner_btn6":
_swfToAdd = _swfClipsArr[5];
break;
}
movie1.removeChildAt(movie1.numChildren-1);
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
}
}
function frameNumberText(evt:Event):void {
frames=_swfToAdd.currentFrame;
textf.text = (String(frames)+" / " + _swfToAdd.totalFrames );
}
function nextClipLOAD(event:Event):void {
if(_swfToAdd.currentFrame == _swfToAdd.totalFrames)
{
index++;
_swfToAdd = _swfClipsArr[index];
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
}
}
Last edited by letschillout; 10-21-2010 at 02:01 AM.
Charag - 3D, Flash Games, Animations,
Website Development & More...
-
Flash/Flex Developer
Two things. Can you place your code with code tags so it minimizes the scrolling and second, do your looping code work or are you getting an error?
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
-
Flash Genie
-
Flash Genie
this is update code, work fine
you can save $10 for rotating banner
the banner call swf from xml and once each reaching last frame of swf then
automatically loads next swf,
Code:
stop();
/*
=======================================
NOTE: ALL SWF FILES must b AS3 exported
http://www.beautifycode.com/the-finer-art-of-loading-2-handling-multiple-swfs#snippet
=======================================
*/
import flash.events.*;
import flash.display.*;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
import fl.motion.Color;
import flash.geom.ColorTransform;
var cTransform:ColorTransform = transform.colorTransform;
var _tintColor:Color;
var _Colored:Color;
var i:uint;
var myXML:XML = new XML();
var XML_URL:String = "banner.xml";
var indexSWF = 0;
var frames:Number;
var _swfLoader:Loader;
var _swfRequest:URLRequest;
var _swfClipsArr:Array = new Array();
var _swfTempClip:MovieClip;
var _loadedSWFs:int;
var _swfToAdd:MovieClip;
var index = 0;
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
/*
=============
METHOD - I
=============
*/
//call link in XML Banner tag
//Converting XML LIST into XML Array
var bannerList:XMLList = myXML.banner.link;
var BannerArray:Array = new Array();
for each (var tempXML:XML in bannerList)
{
BannerArray.push(tempXML);
}
/*
=============
METHOD - II
=============
*/
//var BannerArray:Array = new Array("00.swf", "01.swf", "02.swf");
/*
=============
METHOD - III
=============
*/
/* var arrayLoader:Loader = new Loader;
var thisMovieClip:MovieClip;
var frames:Number
var swf_URL:String = "rbd_fastsaver.swf";
var swfURL:URLRequest = new URLRequest(swf_URL);
arrayLoader.load(swfURL)*/
/*
=============
*/
startLoading(BannerArray);
function startLoading(pathArr:Array):void {
_swfLoader = new Loader();
_swfRequest = new URLRequest();
loadSWF(pathArr[0]);
//trace (loadSWF(pathArr[0])); //rbd_generic.swf
}
function loadSWF(path:String):void {
//checking contentLoaderInfo
setupListeners(_swfLoader.contentLoaderInfo);
_swfRequest.url = path;
//trace(_swfRequest.url);//*.swf
_swfLoader.load(_swfRequest);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
}
function currentSwfProgress(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
// swfPreloader.percentTF.text = _perc + "%";
}
//
function onSwfComplete(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
_swfTempClip = event.target.content;
_swfTempClip.customID = _loadedSWFs;
//trace("ID: " + _swfTempClip.customID);
_swfClipsArr.push(_swfTempClip);
//trace(_loadedSWFs);
if(_loadedSWFs <BannerArray.length - 1) {
_loadedSWFs++;
loadSWF(BannerArray[_loadedSWFs]);
trace(BannerArray[_loadedSWFs]);
} else {
_swfLoader.unloadAndStop();
_swfLoader = null;
onCompletePreloading();
}
}
function onCompletePreloading():void {
_Colored = new Color();
_Colored.setTint (0x000000,1);
banner_btn0.transform.colorTransform = _Colored;
_swfToAdd = _swfClipsArr[0];
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
textf.addEventListener(Event.ENTER_FRAME, frameNumberText);
stage.addEventListener(Event.ENTER_FRAME, nextClipLOAD);
banner_btn0.addEventListener(MouseEvent.CLICK, setContent);
banner_btn1.addEventListener(MouseEvent.CLICK, setContent);
banner_btn2.addEventListener(MouseEvent.CLICK, setContent);
banner_btn3.addEventListener(MouseEvent.CLICK, setContent);
banner_btn4.addEventListener(MouseEvent.CLICK, setContent);
banner_btn5.addEventListener(MouseEvent.CLICK, setContent);
}
function changeColor():void {
}
function backColor(event:MouseEvent):void {
_tintColor = new Color();
_tintColor.setTint (0,0);
event.target.transform.colorTransform = _tintColor;
}
function setContent(event:MouseEvent):void {
trace(event.target.name);
_tintColor = new Color();
_tintColor.setTint (0,0);
event.target.transform.colorTransform = _Colored;
switch(event.target.name) {
case "banner_btn0":
_swfToAdd = _swfClipsArr[0];
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
index = 0;
break;
case "banner_btn1":
_swfToAdd = _swfClipsArr[1];
banner_btn0.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
index = 1;
break;
case "banner_btn2":
_swfToAdd = _swfClipsArr[2];
banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
index = 2;
break;
case "banner_btn3":
_swfToAdd = _swfClipsArr[3];
banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
index = 3;
break;
case "banner_btn4":
_swfToAdd = _swfClipsArr[4];
banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
index = 4;
break;
case "banner_btn5":
_swfToAdd = _swfClipsArr[5];
banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
index = 5;
break;
}
movie1.removeChildAt(movie1.numChildren-1);
_swfToAdd.gotoAndStop(_swfToAdd.totalFrames);
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
}
}
function frameNumberText(evt:Event):void {
frames=_swfToAdd.currentFrame;
//textf.text = (String(frames)+" / " + _swfToAdd.totalFrames );
}
function nextClipLOAD(event:Event):void {
if(_swfToAdd.currentFrame == _swfToAdd.totalFrames)
{
index++;
trace(index);
if (index > 0)
{
var data2 = "banner_btn" + index ;
_swfToAdd = _swfClipsArr[index];
trace(String(data2));
_tintColor = new Color();
_tintColor.setTint (0,0);
banner_btn0.transform.colorTransform = _tintColor;
banner_btn1.transform.colorTransform = _tintColor;
banner_btn2.transform.colorTransform = _tintColor;
banner_btn3.transform.colorTransform = _tintColor;
banner_btn4.transform.colorTransform = _tintColor;
banner_btn5.transform.colorTransform = _tintColor;
if (this[String(data2)]){
_Colored = new Color();
_Colored.setTint (0x000000,1);
this[String(data2)].transform.colorTransform = _Colored;
//banner_btn2.transform.colorTransform = _Colored;
}
}
if (index >= _swfClipsArr.length)
{
index = 0;
banner_btn0.transform.colorTransform = _Colored;
_swfToAdd = _swfClipsArr[index];
}
movie1.removeChildAt(movie1.numChildren-1);
_swfToAdd.gotoAndStop(_swfToAdd.totalFrames);
_swfToAdd.gotoAndPlay(1);
movie1.addChild(_swfToAdd);
_swfToAdd.gotoAndPlay(1);
}
}
Charag - 3D, Flash Games, Animations,
Website Development & More...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|