问题描述
我试图加载在2图片到我的Flash文件,但得到一个错误 - 新本AS3说大话任何帮助,将AP preciated
获取错误:5 1151:存在冲突与定义请求在命名空间内部的
VAR MYIMAGE:字符串= dynamicContent.Profile [0] .propImage.Url;
VAR myImage2:字符串= dynamicContent.Profile [0] .prop2Image.Url;
VAR myImageLoader:StudioLoader =新StudioLoader();
VAR要求:的URLRequest =新的URLRequest(enabler.getUrl(MYIMAGE));
myImageLoader.load(要求);
myImageLoader.x = 17;
myImageLoader.y = 0;
VAR myImageLoader2:StudioLoader =新StudioLoader();
VAR要求:的URLRequest =新的URLRequest(enabler.getUrl(myImage2));
myImageLoader.load(要求);
myImageLoader.x = 17;
myImageLoader.y = 0;
如果(this.currentFrame == 1){
addChildAt(myImageLoader,2);
}
如果(this.currentFrame == 2){
addChildAt(myImageLoader2,2);
}
它通常是一个好主意,做移动复制粘贴+重复code到它自己的函数:
函数的LoadImage(文件:字符串,X:数x,y:号码):StudioLoader {
VAR myImageLoader:StudioLoader =新StudioLoader();
VAR要求:的URLRequest =新的URLRequest(文件);
myImageLoader.load(要求);
myImageLoader.x = X;
myImageLoader.y = Y;
返回myImageLoader;
}
的addChild(的LoadImage(enabler.getUrl(myImage1),17,0));
的addChild(的LoadImage(enabler.getUrl(myImage2),17,0));
这不只是给你更好的结构化code,但也修复你重复的变量定义的问题,因为什么是函数内局部定义停留在函数内部。
这可能会提供一些见解:
的
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);
}
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
这篇关于加载多个孩子像AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!