Skip to main content
Inspiring
September 23, 2013
Question

declare moviclip using array in .as file

  • September 23, 2013
  • 2 replies
  • 885 views

Hi ,

I have create created movieclip with children in the fla

In item.as file

var item1_arr:Array=new Array(item.item_mc1,item.item_mc2,.....)

it is showing error.

Cannot access a property or method of a null object reference

then i have changed to

var item1_arr:Array=new Array("item.item_mc1","item.item_mc2",.....)

then again i am getting the error.

please anyone help me how to access these moviclip by using an array

This topic has been closed for replies.

2 replies

Amy Blankenship
Legend
September 23, 2013

It seems to me that probably item is a movie clip you're adding to the stage either on the timeline or in code. The code that runs in the part of the Class where you declare variables runs before the constructor. I don't understand why your string code would fail, as it isn't actually referencing this nonexistent item. However, it probably wouldn't do much for you for precisely this reason.

Why do you need to store this information in this form anyway, since you will at some point acquire a reference to item, which will contain those references at that time and you could just reference them directly?

Inspiring
September 23, 2013

If item is a class you made, or a movie clip which contains other MovieClips that you named "item_mc1",""item_mc1") etc.

you have to reference these movielicps with this.item_mc1 not item.item_mc1 from within the class.

Inspiring
September 23, 2013

i want to keep it in array, but this.item_mc1... i can't keep it in array right. If i keep it array like that it is showing error

Inspiring
September 23, 2013

I have no clue, how your file is structured in detail so its hard to for me to guess what you wnt to achieve.

Generally: putting a series of objects into an array is only posssible if they already are created:

so the procedure is sth. like this:

var _array:Array = new Array();

for (var i:int = 1; i<=10;i++){

        var _object:Object = new Object();

       _object.name = "object"+i;

      _array.push(_object);

}

trace(_arr[9].name);

//results in object9