Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

declare moviclip using array in .as file

Participant ,
Sep 22, 2013 Sep 22, 2013

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

TOPICS
ActionScript
849
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 23, 2013 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 23, 2013 Sep 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 23, 2013 Sep 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 23, 2013 Sep 23, 2013

Okay thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 23, 2013 Sep 23, 2013
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines