1

I'm trying to load 2 images in to my flash file but getting an error - new to this AS3 malarkey any help would be appreciated!

Getting error: 5 1151: A conflict exists with definition request in namespace internal.

var myImage:String = dynamicContent.Profile[0].propImage.Url;
var myImage2:String = dynamicContent.Profile[0].prop2Image.Url;

var myImageLoader:StudioLoader = new StudioLoader();
var request:URLRequest = new URLRequest(enabler.getUrl(myImage));
myImageLoader.load(request);
myImageLoader.x =17;
myImageLoader.y = 0;

var myImageLoader2:StudioLoader = new StudioLoader();
var request:URLRequest = new URLRequest(enabler.getUrl(myImage2));
myImageLoader.load(request);
myImageLoader.x =17;
myImageLoader.y = 0;

if(this.currentFrame == 1) {
     addChildAt(myImageLoader, 2);
}

if(this.currentFrame == 2) {
     addChildAt(myImageLoader2, 2);
}
Dave
  • 108
  • 2
  • 15

3 Answers3

2

It's usually a good idea to move duplicate code into its own function instead of doing copy + paste:

function loadImage(file:String, x:Number, y:Number):StudioLoader{
    var myImageLoader:StudioLoader = new StudioLoader();
    var request:URLRequest = new URLRequest(file);
    myImageLoader.load(request);
    myImageLoader.x = x;
    myImageLoader.y = y;
    return myImageLoader;
}
addChild(loadImage(enabler.getUrl(myImage1),17,0));
addChild(loadImage(enabler.getUrl(myImage2),17,0));

That's not just giving you better structured code but also fixes your duplicate variable definition issue because what's defined locally inside a function stays inside the function.

This might provide some insight:

http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/functions.html

Malte Köhrer
  • 1,577
  • 10
  • 19
  • Do you know how you add the size of the image? I'm using the same image for a few different sized banners at it's being stretched over the whole thing... myImageLoader.height = 200; for example isnt working – Dave Mar 16 '15 at 08:38
  • You need to wait until the image has been loaded before you can set the size. See http://stackoverflow.com/questions/3792979/how-to-resize-dynamically-loaded-image-into-flash-as3 – Malte Köhrer Mar 19 '15 at 13:26
1

You can't create a new variable with the same name as an existing one, in your case I'm speaking about your URLRequest request, so to avoid this type of error you can do like this :

var myImageLoader2:StudioLoader = new StudioLoader();
// assing a new URLRequest to an existing var
request = new URLRequest(enabler.getUrl(myImage2));
// here you want use the myImageLoader2, not myImageLoader
myImageLoader2.load(request);
myImageLoader2.x =17;
myImageLoader2.y = 0;

Or :

var myImageLoader2:StudioLoader = new StudioLoader();
// create a new URLRequest var, so the name should be different
var request2:URLRequest = new URLRequest(enabler.getUrl(myImage2));
// here you want use the myImageLoader2, not myImageLoader
myImageLoader2.load(request2);
myImageLoader2.x =17;
myImageLoader2.y = 0;
akmozo
  • 9,829
  • 3
  • 28
  • 44
0

Additionally, I notice in the second block that you declare myImageLoader2 but you then use the original myImageLoader to do the load request. So even if you do declare a new URLRequest, you wont get both images loaded.

Akmozo's solution has this corrected.