-1

i use txt file that contain paths. after loaded txt file and split to path array then load img file from array path but i get err in loading img

please help me

sample code:

var imglst:Array=new Array();
var lodimg:Loader=new Loader();
var lodtxt:URLLoader=new URLLoader();

lodtxt.load(new URLRequest("imglst.txt"));
lodtxt.addEventListener(Event.COMPLETE,onL_C);

function onL_C(e:Event)
{
 var t:Array=new Array();
 t=e.target.data.split(/\n/);
 var s:URLRequest=new URLRequest(t[0].toString());
 trace(t[0]);
 lodimg.load(s);
}

lodimg.contentLoaderInfo.addEventListener(Event.COMPLETE,onL_Cimg);


function onL_Cimg(e:Event)
{
 var i:Bitmap=new Bitmap();
 i=Bitmap(lodimg.content);
 i.width=100;
 i.height=100;
 addChild(i);
 trace("OK");
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
mesoft
  • 1
  • What error do you get? This question lacks research effort and basically asks "fix my code". Voting to close. – null Aug 22 '15 at 15:32
  • Show us the text file, the error, and directory tree. Right now there is no way how we can help you. – Darth Hunterix Aug 22 '15 at 15:33

1 Answers1

0

Are you loading images from a different website from your own? Does the other website(s) have a crossdomain.xml to allow permissions of loading their content? Usually Flash will give you a "security error" as an event but your code isn't listening for such an event so your program is not aware of any such problems... look on google how to handle AS3 errors.

Anyways a workaround is to just load the bytes of file using URLloader and on completion you then only use Loader to decode the bytes into pixel colours.

import flash.utils.ByteArray;

var imglst : Array;
var lodimg : Loader;
//var lodtxt : URLLoader = new URLLoader();

var lodURL:URLLoader = new URLLoader();
var img_bytes : ByteArray = new ByteArray();

lodURL.load(new URLRequest("http://yoursite/imglst.txt"));
lodURL.addEventListener(Event.COMPLETE,onL_C);

function onL_C (e:Event)
{
    //# Since load complete no need to keep listening for that
    lodURL.removeEventListener(Event.COMPLETE,onL_C);

    var t:Array=new Array();
    t=e.target.data.split(/\n/);
    var s:URLRequest=new URLRequest(t[0].toString());
    trace(t[0]);

    //lodimg.contentLoaderInfo.addEventListener(Event.COMPLETE,onL_Cimg);
    //lodimg.load(s);

    //# Now we know path so we load those file bytes
    lodURL.dataFormat = URLLoaderDataFormat.BINARY;
    lodURL.load(s); lodURL.addEventListener(Event.COMPLETE, onBytes_C);

}

function onBytes_C (e:Event)
{
    //# on complete load of bytes...
    trace("got bytes");
    img_bytes = lodURL.data; 
    //trace("Image bytes total : " + img_bytes.length);
    img_bytes.position = 0; //avoid "end of file" error

    lodimg = new Loader();
    lodimg.contentLoaderInfo.addEventListener(Event.COMPLETE,onL_Cimg);
    lodimg.loadBytes(img_bytes); //we already have data so this will be fast

}

function onL_Cimg (e:Event)
{
    var i:Bitmap = new Bitmap(); 
    i = lodimg.content as Bitmap;

    i.width=100;
    i.height=100;
    addChild(i);
    trace("OK");
}
VC.One
  • 14,790
  • 4
  • 25
  • 57