TOM
TOM

Reputation: 881

How To Load Image Though URL in action script 3.0

I have tested the code in action script 2.0 . it is working great but it does not support GIF so i want it write in action script 3.0. But i have no idea in this.

 var current_loader: Number = 1;
 import flash.geom.*;
 var current_img: Number = 0;
 this.createEmptyMovieClip('img_01', 999);
 this.createEmptyMovieClip('img_02', 998);
 var loader: MovieClipLoader = new MovieClipLoader();
 var listener: Object = new Object();

 listener.onLoadComplete = function (target_mc: MovieClip) {
     if (target_mc._name == 'img_01') {
         img_02._visible = false;
     } else {
         img_01._visible = false;
     }
     progress_bar.visible = true;
     current_loader.opaqueBackground = 0xFF0000;
 };

 var interval: Number = setInterval(load_image, 1000);

 function load_image() {
     loader.addListener(listener);
 }

 loader.loadClip("http://google/Example3", current_loader);
 current_loader = current_loader == 1 ? 2 : 1;
 current_img = current_img == images.length - 1 ? 0 : current_img + 1;
 }

Upvotes: 1

Views: 6724

Answers (3)

TOM
TOM

Reputation: 881

i did like this .And its Working Perfectly.i think it is the simplest .

 package 
    {           
     import flash.display.Loader;            
     import flash.display.Sprite;             
     import flash.net.URLRequest;           
     import flash.utils.Timer;            
     import flash.events.TimerEvent;                
     import flash.events.Event;               

public class Example extends Sprite {
    public function Example() {
        var myTimer:Timer = new Timer(1000);// 1 second
        myTimer.addEventListener(TimerEvent.TIMER,runMany);
        myTimer.start();
        function runMany(e:TimerEvent):void {
            var loader:Loader=new Loader();
            var url:String= "http://Google.Example3.com/latimage.php";
            loader.load(new URLRequest(url));
            addChild(loader);
        }
    }
  }
}

Upvotes: 1

Stefan van de Vooren
Stefan van de Vooren

Reputation: 2707

Very simple in as3: open Flash IDE, create new .fla file, select first frame, open 'actions (f9)' copy code.

Of course in AS3 it's better to use classes to put your code in. enter image description here

import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;

var imageLoader:Loader = new Loader();
var request:URLRequest = new URLRequest("http://dummyimage.com/600x400/e000e0/fff.gif");
imageLoader.load(request);

addChild (imageLoader);

// and all possible listeners
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
imageLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS,  httpStatusHandler);
imageLoader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
imageLoader.contentLoaderInfo.addEventListener(Event.OPEN, openHandler);

imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);


function completeHandler(event:Event):void {
    trace("completeHandler: " + event);
}

function httpStatusHandler(event:HTTPStatusEvent):void {
    trace("httpStatusHandler: " + event);
}

function initHandler(event:Event):void {
    trace("initHandler: " + event);
}

function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
}

function openHandler(event:Event):void {
    trace("openHandler: " + event);
}

function progressHandler(event:ProgressEvent):void {
    trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}

see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#includeExamplesSummary

Upvotes: 3

Andrew Sellenrick
Andrew Sellenrick

Reputation: 1016

There are simpler ways using straight as3 but this a robust way to load may file types with lots of great documentation. https://greensock.com/LoaderMax-AS3

Upvotes: 1

Related Questions