Skip to main content
lukem42844010
Participating Frequently
January 9, 2017
Answered

Making an array containing images and adding them to the stage HELP!!

  • January 9, 2017
  • 1 reply
  • 1301 views

I have an assignment where I am to make a game similar to bloons where balls drop from the sky. However we've yet to be taught anything. I really need help with the array containing the images. I have a set of images;

blueBall

bombBall

greenBall

redBall

yellowBall

how can I add these into an array and addChild them in a random order and amount five in a row at a time?

Luke

This topic has been closed for replies.
Correct answer kglad

ArgumentError: Error #1507: Argument name cannot be null.

  at global/flash.utils::getDefinitionByName()

  at Level1Class()

  at GameManagerClass/GoToScene()

  at HomeScreenClass/playButtonClicked()

Its not saying what code is triggering it? But it could be from the C=Class(getDefinitionByName(ballArray));

I used to work with flash but never touched arrays as I couldn't get along with them aha


change this:

for(var i:int=0;i<rowNum;i++){

shuffle(imageA);

for(var j:int=0;j<5;j++){

to:

for(var i:int=0;i<rowNum;i++){

shuffle(imageA);

for(var j:int=0;j<ballArray.length;j++){

1 reply

kglad
Community Expert
Community Expert
January 9, 2017

are those library symbols or bitmaps (eg, png files) that need to be loaded or something else?

lukem42844010
Participating Frequently
January 9, 2017

There images I've drawn myself on CS6 using the pen tool (rather than through code).

Thank you for replying

kglad
Community Expert
Community Expert
January 9, 2017

convert them to symbols (eg, movieclips) and assing each a linkage id (eg, BlueBall, BombBall, etc);

you can then use:

var imageA:Array=['BlueBall','BombBall',etc..];

var xgap:int = ?

var ygap:int = ?

var rowNum:int = ?

var C:Class;

var image:MovieClip;

for(var i:int=0;i<rowNum;i++){

shuffle(imageA);

for(var j:int=0;j<5;j++){

C=Class(getDefinitionByName(imageA));

image=new C();

addChild(image);

image.y=i*ygap;

image.x=j*xgap;

}

}

function shuffle(a:Array) {

    var p:int;

    var t:*;

    var ivar:int;

    for (ivar = a.length-1; ivar>=0; ivar--) {

        p=Math.floor((ivar+1)*Math.random());

        t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

}