srajakaruna
February 11th, 2009, 02:06 AM
I load 7 images and swap images after each 6.5 seconds. But after sometime the tween stops in the middle and shows the next image like a watermark. (Please see the attachment image) How do i avoid this ..
please help
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.*;
import flash.events.*;
import flash.utils.*;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
dynamic public class _slider extends MovieClip{
var _mc:MovieClip = new MovieClip();
var _imgLnth:int = 0;
var _imgInc:int = 0;
var _loopInc:int = 0;
var _arr:Array = new Array();
var _insNames:Array = new Array();
public function _slider(){
var _list:URLLoader = new URLLoader();
_list.load(new URLRequest("_imglist.xml"));
_list.addEventListener(Event.COMPLETE,_initXML);
}
private function _initXML(_e:Event){
var _xml:XML = new XML(_e.target.data);
var _imgList:XMLList = _xml.image;
_imgLnth = _imgList.length();
for (var i:int = 0; i<_imgList.length(); i++){
var _image:XML = _imgList[i];
_arr[i] = [_image.@src,_image.text(),_image.@x,_image.@y];
}
_loadList(_arr,0);
}
private function _loadList(_arr,_no){
this['_ld'+_no+''] = new Loader();
this['_ld'+_no+''].load(new URLRequest(_arr[_no][0]));
this['_ld'+_no+''].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS, _loading);
this['_ld'+_no+''].contentLoaderInfo.addEventListener(Event.COMPLETE , _loaded);
}
function _loading(_e:ProgressEvent){
}
function _loaded(_e:Event){
if (_imgInc==0){
gotoAndStop(2);
this.addChild(_mc);
setChildIndex(_mc,1);
}
_imgInc++;
var _obj = _e.target.loader;
_obj.alpha = 0;
_mc.addChild(_obj);
_mc.setChildIndex(_obj,0);
_insNames[_insNames.length] = _obj.name;
var _tw:Tween = new Tween(_obj, "alpha", Strong.easeOut, 0, 1, 3, true);
if (_imgInc < _imgLnth){
_loadList(_arr,_imgInc);
}else{
var _int:uint = setInterval(_initAnim,6500);
}
}
function _initAnim(){
var _nxt = _loopInc+1;
if (_nxt>_imgLnth-1){
_nxt = 0;
}
var _twx:Tween = new Tween(_mc.getChildByName(_insNames[_loopInc]), "alpha", Strong.easeOut, 1, 0, 3, true);
_twx.addEventListener(TweenEvent.MOTION_FINISH, _twEnd);
_loopInc++;
if (_loopInc>_imgLnth-1){
_loopInc = 0;
}
}
function _twEnd(e:TweenEvent){
_mc.setChildIndex(e.target.obj,0);
e.target.obj.alpha = 100;
}
}
}
please help
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.*;
import flash.events.*;
import flash.utils.*;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
dynamic public class _slider extends MovieClip{
var _mc:MovieClip = new MovieClip();
var _imgLnth:int = 0;
var _imgInc:int = 0;
var _loopInc:int = 0;
var _arr:Array = new Array();
var _insNames:Array = new Array();
public function _slider(){
var _list:URLLoader = new URLLoader();
_list.load(new URLRequest("_imglist.xml"));
_list.addEventListener(Event.COMPLETE,_initXML);
}
private function _initXML(_e:Event){
var _xml:XML = new XML(_e.target.data);
var _imgList:XMLList = _xml.image;
_imgLnth = _imgList.length();
for (var i:int = 0; i<_imgList.length(); i++){
var _image:XML = _imgList[i];
_arr[i] = [_image.@src,_image.text(),_image.@x,_image.@y];
}
_loadList(_arr,0);
}
private function _loadList(_arr,_no){
this['_ld'+_no+''] = new Loader();
this['_ld'+_no+''].load(new URLRequest(_arr[_no][0]));
this['_ld'+_no+''].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS, _loading);
this['_ld'+_no+''].contentLoaderInfo.addEventListener(Event.COMPLETE , _loaded);
}
function _loading(_e:ProgressEvent){
}
function _loaded(_e:Event){
if (_imgInc==0){
gotoAndStop(2);
this.addChild(_mc);
setChildIndex(_mc,1);
}
_imgInc++;
var _obj = _e.target.loader;
_obj.alpha = 0;
_mc.addChild(_obj);
_mc.setChildIndex(_obj,0);
_insNames[_insNames.length] = _obj.name;
var _tw:Tween = new Tween(_obj, "alpha", Strong.easeOut, 0, 1, 3, true);
if (_imgInc < _imgLnth){
_loadList(_arr,_imgInc);
}else{
var _int:uint = setInterval(_initAnim,6500);
}
}
function _initAnim(){
var _nxt = _loopInc+1;
if (_nxt>_imgLnth-1){
_nxt = 0;
}
var _twx:Tween = new Tween(_mc.getChildByName(_insNames[_loopInc]), "alpha", Strong.easeOut, 1, 0, 3, true);
_twx.addEventListener(TweenEvent.MOTION_FINISH, _twEnd);
_loopInc++;
if (_loopInc>_imgLnth-1){
_loopInc = 0;
}
}
function _twEnd(e:TweenEvent){
_mc.setChildIndex(e.target.obj,0);
e.target.obj.alpha = 100;
}
}
}