Regarding Stop blinking in flash Action Script

北城以北 提交于 2019-12-12 01:47:14

问题


Hi i am using flash Action Script. Image is displaying from internet at 1 sec interval. But this is blinking. How can i stop blinking so that i can see images continuously.

    var my_pb:mx.controls.ProgressBar;
my_pb.mode = "manual";
this.createEmptyMovieClip("img_mc", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
    my_pb.label = "loading: "+target_mc._name;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) {
    var pctLoaded:Number = Math.ceil(100*(numBytesLoaded/numBytesTotal));
    my_pb.setProgress(numBytesLoaded, numBytesTotal);
};
var myInterval = setInterval(testInterval, 1000);
function testInterval() {
    my_mcl.addListener(mclListener);
    my_mcl.loadClip("https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif", img_mc);
    //my_mcl.loadClip("https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif", img_mc);
}

回答1:


To avoid that you can use two MovieClips and every time load your image into one of them and hide the other one, like this :

var images:Array = [
    'https://cdn3.iconfinder.com/data/icons/inficons/128/stackoverflow.png',
    'https://cdn3.iconfinder.com/data/icons/inficons/128/joomla.png',
    'https://cdn3.iconfinder.com/data/icons/inficons/128/bitcoin.png',
    'https://cdn3.iconfinder.com/data/icons/inficons/128/wordpress.png',    
    'https://cdn3.iconfinder.com/data/icons/inficons/128/github.png'
];  

var current_loader:Number = 1;
var current_img:Number = 0;

var progress_bar:mx.controls.ProgressBar;
    progress_bar.mode = 'manual';

this.createEmptyMovieClip('img_01', 999);
this.createEmptyMovieClip('img_02', 998);

img_01._x = img_01._y = img_02._x = img_02._y = 20;

var loader:MovieClipLoader = new MovieClipLoader();

var listener:Object = new Object();
    listener.onLoadStart = function(target_mc:MovieClip) {
        progress_bar.visible = true;
    }
    listener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) {
        progress_bar.setProgress(numBytesLoaded, numBytesTotal);
    }
    listener.onLoadComplete = function(target_mc:MovieClip) {
        // hide the last image loader 
        if(target_mc._name == 'img_01'){
            img_02._visible = false;
        } else {
            img_01._visible = false;
        }
        // init the progress bar and hide it
        progress_bar.setProgress(0, 100);
        progress_bar.visible = false;
    }

var interval:Number = setInterval(load_image, 1000);
function load_image() { 
    loader.addListener(listener);
    loader.loadClip(images[current_img], _root['img_0'+current_loader]);
    // set the next loader
    current_loader = current_loader == 1 ? 2 : 1;
    // set next image
    current_img = current_img == images.length - 1 ? 0 : current_img + 1;
}
// load the first image 
load_image();

You can see this code working here.

Sometimes, we can not see the progress bar because image is loaded very fast, of course if you want to use large images, you have to increase your interval.

Hope that can help.



来源:https://stackoverflow.com/questions/28895663/regarding-stop-blinking-in-flash-action-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!