0
A constructor cannot specify a return type.
New Here
,
/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/td-p/772178
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
I have a shuffleList.as file with this code...
package {
import flash.display.MovieClip;
public class shuffleList extends MovieClip{
function shuffleList(arr:Array):Array{
var shuffled:Array = arr.slice();
for (var i:int=0; i<arr.length; i++) {
var element:Object = shuffled ;
var rnd:int = Math.floor(arr.length * Math.random());
shuffled = shuffled[rnd];
shuffled[rnd] = element;
}
return shuffled;
}
}
}
In the first frame i put this code...
import shuffleList
var numA:Array = [0,1,2,3,4,5,6,7,8,9,10]
var numB:Array = shuffleList(numB);
var myText:String = numB.pop()
fieldA.text = myText
With this code I want to put in random order the numbers from 0 to 10 in the fieldA.
When run this file the compiler report this error: "A constructor cannot specify a return type."
Where I'm wrong;
I'm new in actionscript..
Please help...
package {
import flash.display.MovieClip;
public class shuffleList extends MovieClip{
function shuffleList(arr:Array):Array{
var shuffled:Array = arr.slice();
for (var i:int=0; i<arr.length; i++) {
var element:Object = shuffled ;
var rnd:int = Math.floor(arr.length * Math.random());
shuffled = shuffled[rnd];
shuffled[rnd] = element;
}
return shuffled;
}
}
}
In the first frame i put this code...
import shuffleList
var numA:Array = [0,1,2,3,4,5,6,7,8,9,10]
var numB:Array = shuffleList(numB);
var myText:String = numB.pop()
fieldA.text = myText
With this code I want to put in random order the numbers from 0 to 10 in the fieldA.
When run this file the compiler report this error: "A constructor cannot specify a return type."
Where I'm wrong;
I'm new in actionscript..
Please help...
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/m-p/772179#M16225
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
I'm no Class expert, but my first eyeballing of it says to
declare that function as public... the class is public, but I don't
know what status the function has without being declared as private
or public.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/m-p/772180#M16226
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
Hey Petros,
I had a similar problem and the response I got was:
1) the constructor is used to set up the class but it doesn't really exist until it is instantiated and therefore cannot include any 'interaction' including a return.
2) Therefore, you might try replacing
function.shuffleList ... with
function.shuffleList() { // to enable instantiation
}
public function doit(arr:Array):Array { // to enable interaction
The rest of the code follows this then the call in the first frame replaces
var numB:Array ... with
new shuffleList(); // instantiate the class
var numB:Array = shuffleList.doit(numB) // interact with the class
Let me know how it goes...Daniel
I had a similar problem and the response I got was:
1) the constructor is used to set up the class but it doesn't really exist until it is instantiated and therefore cannot include any 'interaction' including a return.
2) Therefore, you might try replacing
function.shuffleList ... with
function.shuffleList() { // to enable instantiation
}
public function doit(arr:Array):Array { // to enable interaction
The rest of the code follows this then the call in the first frame replaces
var numB:Array ... with
new shuffleList(); // instantiate the class
var numB:Array = shuffleList.doit(numB) // interact with the class
Let me know how it goes...Daniel
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Petros121
AUTHOR
New Here
,
/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/m-p/772181#M16227
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
Daniel,
Thank's for your answer..
I change the code as you said and now the compiler report this error:
1067: Implicit coercion of a value of type shuffleList to an unrelated type Array.
Thank's for your answer..
I change the code as you said and now the compiler report this error:
1067: Implicit coercion of a value of type shuffleList to an unrelated type Array.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Petros121
AUTHOR
New Here
,
/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/m-p/772182#M16228
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
Daniel,
I didn't replaced the code in the frame...
So the new code as you said is...
18.var numA:Array = [0,1,2,3,4,5,6,7,8,9,10]
19.new shuffleList(); // instantiate the class
20.var numB:Array = shuffleList.doit(numA) // interact with the class
and now the compiler report this error:
Line 19:1180: Call to a possibly undefined method shuffleList.
Line 20: 1120: Access of undefined property shuffleList.
I didn't replaced the code in the frame...
So the new code as you said is...
18.var numA:Array = [0,1,2,3,4,5,6,7,8,9,10]
19.new shuffleList(); // instantiate the class
20.var numB:Array = shuffleList.doit(numA) // interact with the class
and now the compiler report this error:
Line 19:1180: Call to a possibly undefined method shuffleList.
Line 20: 1120: Access of undefined property shuffleList.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Petros121
AUTHOR
New Here
,
LATEST
/t5/animate-discussions/a-constructor-cannot-specify-a-return-type/m-p/772183#M16229
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
If i put the function in the frame
everything is O.K.
everything is O.K.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

