Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

As3IsoLib: Loading Image and Adding to Sprite.

New Here ,
Nov 12, 2012 Nov 12, 2012

I'm using a library called 'As3IsoLib' in my isometric game to create sprites and other elements. Currently I add a sprite and load an image to be displayed for the sprite. Up until now I have not checked to see when the image has actually loaded as I just straight away add it. That's got me thus far but now I'm expericening 'security' errors in flash which apparently mean it's trying to add an image which hasn't yet fully loaded.

Since I was going to be loading lots of images I put such under a function entitled 'LoadImg'. This is passed a string that is the location of the image we wish to load.

var UnitSprite:IsoSprite;

UnitSprite.moveTo(0, 0, 0);

UnitSprite.sprites=[LoadImg('imgs/picture.png')];

DrawSprite(UnitSprite);

function LoadImg(Img:String):Loader

     {

     var myLoader:Loader;

     myLoader=new Loader();

     myLoader.load(new URLRequest(Img));

   

     return myLoader;

     }

But now I need to say when it's completed loading the image then return the loader which isn't possible. I can't add an event handler saying when the 'myLoader' has completed because then you have to supply a second function rendering me unable to use return. I also cannot pass it the sprite I wish to add the image to. I've read in AS2 you were able to pass additional arguments. Such would solve my problem via something along the lines of...

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, AddImg(SpriteToAddImgTo));

function AddImg(e:Event,Spr:IsoSprite)

   {

    Spr.sprites = [e.target];

   }

But I'm using AS3 so I cannot do such. I've read several times on the Internet that it is possible to pass addional arguments ( see http://sinfinity.pl/blog/2012/03/28/adding-parameters-to-event-listener-in-flex-air-as3/ )

but I cannot get it to work. How might I achieve this?

TOPICS
ActionScript
999
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2012 Nov 12, 2012

copy and paste the complete security error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2012 Nov 12, 2012

SecurityError: Error #2000: No active security context.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2012 Nov 12, 2012
LATEST

that may (or may not) be caused by trying to use the loader's content before loading is complete.  to remedy the problem, if it's caused by trying to use the loader's content before loading is complete use:

var UnitSprite:IsoSprite;UnitSprite.moveTo(0, 0, 0);

     var myLoader:Loader;

LoadImg('imgs/picture.png');

function LoadImg(Img:String):void     {myLoader=new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, AddImg);    myLoader.load(new URLRequest(Img));     }

function AddImg(e:Event)   {Spr.sprites = [e.target];UnitSprite.sprites=Bitmap(myLoader.content);  
DrawSprite(UnitSprite); }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines