Copy link to clipboard
Copied
the code below is trying to generate a raw object, duplicate it n times and, replace it in a different random position
so i made the code in this way:
var dustRaw:MovieClip;
var dust:MovieClip;function dustRawGen() {
dustRaw.graphics.beginFill(0xFF0000);
dustRaw.graphics.drawEllipse(0,0,1,1);
dustRaw.graphics.endFill();
}function dustGen() {
for (var i:int = dustArray.length; i<=dustCount-1; i++) {
dust = new dustRaw();
addChild(dust);
dust.x = Math.random() * (rBound-lBound) + lBound;
dust.y = Math.random() * (dBound-uBound) + uBound;
dustArray.push(dust);
tailArray = new Array();
}
}dustRawGen();
dustGen();
but when i test it, there is an error on the bolded line
1180: Call to a possibly undefined method dustRaw.
did anyone know why?
thanks for any help
1 Correct answer
if dustRaw is an ellipse creating class, you would use it from another class. for example, if you want to use it from the dustGen class:
...
// dustRaw.as:
package{
import flash.display.MovieClip;
class dustRaw extends MovieClip {
public function dustRaw(){
graphics.beginFill(0xFFFFFF);
graphics.drawEllipse(0,0,15,15);
graphics.endFill();
}}
}
// dustGen.as:
package{
import dustRaw;
public class dustGen{
private v
Copy link to clipboard
Copied
you don't hav a dustRaw class in that scope.
Copy link to clipboard
Copied
oic, then i rewrite it so the code becomes:
class dustRaw extends MovieClip {
graphics.beginFill(0xFFFFFF);
graphics.drawEllipse(0,0,15,15);
graphics.endFill();
}function dustGen() {
for (var i:int = dustArray.length; i<=dustCount-1; i++) {
dust = new dustRaw();
addChild(dust);
dust.x = Math.random() * (rBound-lBound) + lBound;
dust.y = Math.random() * (dBound-uBound) + uBound;
dustArray.push(dust);
tailArray = new Array();
}
}
but why later it gives me error 1131 which says "Classes must not be nested."
i never nested classes above...
thanks for helping again
Copy link to clipboard
Copied
that code must be a snippet because it makes no sense as written.
Copy link to clipboard
Copied
sorry but i dont understand because i am a beginner only...
Copy link to clipboard
Copied
there are so many problems with that code there must be more to that class file. the first error is in line 1, there's no package specified.
Copy link to clipboard
Copied
sorry can you demonstrate for me?
because i am learning as3 by CIB and "Programming actionsctipt 3.0" only
i took reference from CIB and converted the codes.
package{
import flash.display.MovieClip;
class dustRaw extends MovieClip {
public function dustRaw(){
graphics.beginFill(0xFFFFFF);
graphics.drawEllipse(0,0,15,15);
graphics.endFill();
}}
}
function dustGen() {
for (var i:int = dustArray.length; i<=dustCount-1; i++) {
dust = new dustRaw();
addChild(dust);
dust.x = Math.random() * (rBound-lBound) + lBound;
dust.y = Math.random() * (dBound-uBound) + uBound;
dustArray.push(dust);
tailArray = new Array();
}
}
then the compiler gave me such error:
Scene 1, Layer 'actions', Frame 1, Line 128 1083: Syntax error: package is unexpected.
thanks again and again...
Copy link to clipboard
Copied
if dustRaw is an ellipse creating class, you would use it from another class. for example, if you want to use it from the dustGen class:
// dustRaw.as:
package{
import flash.display.MovieClip;
class dustRaw extends MovieClip {
public function dustRaw(){
graphics.beginFill(0xFFFFFF);
graphics.drawEllipse(0,0,15,15);
graphics.endFill();
}}
}
// dustGen.as:
package{
import dustRaw;
public class dustGen{
private var dust:dustRaw
public function dustGen() {
for (var i:int = dustArray.length; i<=dustCount-1; i++) {
dust = new dustRaw();
addChild(dust);
dust.x = Math.random() * (rBound-lBound) + lBound;
dust.y = Math.random() * (dBound-uBound) + uBound;
dustArray.push(dust);
tailArray = new Array();
}
}}
}
p.s. you should use generally accepted coding standards: your class names should start with an upper case letter, eg DustGen and DustRaw would be what coders expect to see.
Copy link to clipboard
Copied
ic, thanks.
Copy link to clipboard
Copied
you're welcome.

