Skip to main content
Inspiring
December 11, 2013
Answered

Error #1056: Cannot create property 0 on String.

  • December 11, 2013
  • 2 replies
  • 14614 views

I found similar posts about this but was unable to find my situation.

I have 2 arrays, One is filled out earlier in the program by user inputs in the following format:

VideoArray[0] : nothing

VideoArray[1] : [Object]

VideoArray[1][0]: String (this string is inputed by the user in a text field)

VideoArray[1][1]: String (this string is inputed by the user in a text field)

It then follows the pattern of user inputs:

[2]:Object

[2][0]:string

[2][1]:string

[3]

[3][0]

[3][1]

... repeat for as long as the user inputs data.

I am trying to copy the data into another array using a series of loops since i wont know how many sets of data the user inputs. i dont need the object data in the new array. The new array (InfoArray) will be structured like so:

InfoArray[0]: String

InfoArray[1]: Number

InfoArray[2]: nothing

InfoArray[2][0]: VideoArray[1][0]

InfoArray[2][1]: VideoArray[1][1]

InfoArray[3][0]: VideoArray[2][0]

InfoArray[3][1]: VideoArray[2][1]

.. repeat untill all the data is copied.

I do this with the following:


ArrayCount = VideoArray.length + QuestionArray.length + 2



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



{




if (i == 0)




{





InfoArray=ModuleName;




}else




{





if (i == 1)






{







InfoArray=Number_Of_Videos;





}else






{







if(i <=Number_Of_Videos + 2)






{







InfoArray=[];






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






{







trace("i = "+i);







trace("j = "+j);







trace("VideoArray[i-1]: "+ VideoArray[i-1]);







InfoArray = "Video: ";

Line 272




InfoArray = VideoArray[i-1];






}





}else






{

(not sure why it copied the code like this, I couldnt find an "insert code" button)

When I run it I get my traces and the error:

i = 2

j = 0

VideoArray[i-1]: v1

ReferenceError: Error #1056: Cannot create property 0 on String.

          at BWSModuleGenerator_fla::MainTimeline/Compile_Info()[BWSModuleGenerator_fla.MainTimeline::frame1:272]

Ive never gotten this error before, and im not sure whats wrong with my coding.

thanks for any help.

This topic has been closed for replies.
Correct answer Ned Murphy

It is a little confusing trying to follow your data storage scheme, and that might be a big part of the problem, but for the two lines you show...

InfoArray = "Video: ";

InfoArray = VideoArray[i-1];

If the first is a string, the second cannot be an element of an array if that is the intent.  It appears the compiler sees it as if to be trying to target a property of a string using the bracket notation where the at the end is being interpretted as a property, not an index of an array.



2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
December 11, 2013

It is a little confusing trying to follow your data storage scheme, and that might be a big part of the problem, but for the two lines you show...

InfoArray = "Video: ";

InfoArray = VideoArray[i-1];

If the first is a string, the second cannot be an element of an array if that is the intent.  It appears the compiler sees it as if to be trying to target a property of a string using the bracket notation where the at the end is being interpretted as a property, not an index of an array.


JordanDJAuthor
Inspiring
December 11, 2013

talk about hitting the nail on the head.

Your assumption of my intent was correct, as was the issue. I removed "InfoArray = "Video: "; and it works. It wasnt really needed, just made my traces easier to read. I understand what happened now, Thank you very much. so my follow up question would be:

Is there a way to make that work? Is there a way to just change the syntax of the line? like add a comma after the 1st bracket or something? or would i need to do a compeltly different approach if i did need that string there?

Ned Murphy
Legend
December 16, 2013

If you explain your intentions for the data it will be easier to help identify a solution that fits the situation better.

One thing you might consider is to store individual sets of data as Objects, and you can store these Objects in an Array.  An Object can have as many properties as you like, including Arrays within it.  Example....

InfoArray[0] = {objString: "String:", objNumber: 23, videoArray: [ ] };

   


kglad
Community Expert
Community Expert
December 11, 2013

for a shallow copy, use:

infoArray = VideoArray.slice();