[英]AS3 - Pass Array from Custom Class To Main.as
I'm trying to get my array from a custom class so I can use on my main.as file. 我正在尝试从自定义类中获取数组,以便可以在main.as文件中使用。
Here is what I'm working with. 这是我正在使用的。
Main.as: Main.as:
function searchPrize(e:MouseEvent):void
{
var searched_number:Pcnsearch = new Pcnsearch();
searched_number.searchNum(pcn.text,'fueltest',this.stage);
// trying to get the array "CReturn from custom class to trace out
var number_arr:Array = new Array(searched_number.returnSearch());
trace(number_arr.fName);
}
Custom Class: (snippet) 自定义类别:(摘要)
public var cReturn:Array = new Array();
public function loader_completed(e:Event)
{
var person:URLVariables = new URLVariables(e.target.data);
this.cReturn.pcn = person.one;
this.cReturn.fName = person.five;
this.cReturn.lName = person.six;
}
public function returnSearch()
{
return cReturn;
}
what am I doing wrong that is causing me to not return the array into my main.as file? 我在做什么错导致我无法将数组返回到main.as文件中?
any help would be great, Thanks, 任何帮助都会很棒,谢谢,
Your problem is that you assign a new Array() on number_arr with the array from the class as a parameter. 您的问题是您在number_arr上分配了一个新的Array(),并将类中的数组作为参数。 This means that it will return an array with your array inside of it.
这意味着它将返回一个数组,其中包含您的数组。 So you're accessing it wrong.
因此,您访问错误。
Any parameters passed to new Array()
will be elements in the newly created array. 传递给
new Array()
任何参数将是新创建的数组中的元素。 What you can do is instead just use number_arr:Array = searched_number.returnSeach()
您可以做的只是使用
number_arr:Array = searched_number.returnSeach()
Other than that everything else looks fine and you should have no problem accessing the array returned by your class. 除此之外,其他一切看起来都不错,并且访问类返回的数组应该没有问题。
The cReturn is not being populated before it is being returned. 在返回之前,不会填充cReturn。
The steps it takes are: 采取的步骤是:
What I want it to do is: 我想要它做的是:
I will have to use a dispatchEvent inside my loader_complete method (Pcnsearch.as class) with an eventListener inside my main.as script. 我将不得不在loader_complete方法(Pcnsearch.as类)内使用一个dispatchEvent,在main.as脚本内使用一个eventListener。
Thanks for the help. 谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.