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

Error #1056: Cannot create property 0 on String.

Explorer ,
Dec 11, 2013 Dec 11, 2013

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.

TOPICS
ActionScript
14.4K
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

correct answers 1 Correct answer

LEGEND , Dec 11, 2013 Dec 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.

Translate
Community Expert ,
Dec 11, 2013 Dec 11, 2013

for a shallow copy, use:

infoArray = VideoArray.slice();

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
LEGEND ,
Dec 11, 2013 Dec 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.

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
Explorer ,
Dec 11, 2013 Dec 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?

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
LEGEND ,
Dec 15, 2013 Dec 15, 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: [ ] };

   

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
Explorer ,
Dec 17, 2013 Dec 17, 2013
LATEST

sorry for the late response and the large post, i hope it isnt too much for these forums. I wanted to be detailed since you mentioned that if i explain my intentions better it would be easier to help.

I will do my best to explain what i am doing and trying to do, i know its hard to understand without knowing everything and without being in my head and seeing the whole picture, and i appreciate the help.

This all centers around some online training i am creating. The training is a series of videos followed by a quiz. The training module is hosted on my company's sharepoint site and through SCORM records all the data.

I made a training module template in flash and all the other people i work with have to do is go into the Module.FLA and adjust the variables:

Module Name

How many videos

Video 1 name.FLV

Video 1 caption text

video 2 name.FLV

Video 2 caption text

etc

how many questions

how many of those questions will be pulled from the pool (randomly pull 20 of the 30 total questions)

question 1

answer 1

answer 2

etc

correct answer

company SOP that verifies the correct answer

type of question (multiple choice, T/F, Fill in blank, Order the steps, etc)

This isnt difficult, however, the other people i work with have 0 coding experience, let alone AS3. And they constantly mess up my code by deleting random syntax items. (" marks, // marks, and other small things). So i am making a Module generator.

This generator gives them an interface where they can enter all the variable information. They will then hit a button "Publish" this button will consolidate all the information they entered and place it into a file that my original module program will read, thus, they no longer have to go into the module.fla and manually change variables.

the feature i am working on now, is a save and load system. So if they are in the middle of creating a module and they need to quit and come back later, they can save the information they have entered, then later load it.

I have been storing all the information they enter into an array, then saving it using a bytearray: (I am saving all the information into one byte array because it is the only method i know)

for(var i:int = 0; i<InfoArray.length; i++)

          {

                    SaveBA.writeUTF(InfoArray);

          }

InfoArray gets its information from two other arrays:

VideoArray

and

QuestionArray

When using the program, they enter the video information:

Video Name (the FLV file name)

and Video Caption (the closed caption script)

i use the following to create the visual representation and to store the data:

Number_Of_Videos ++;

          VideoArray[Number_Of_Videos] = new MC_Video_Box;

          VideoArray[Number_Of_Videos].name = "Video"+Number_Of_Videos;

...

Video_Info();

The Video_info function brings up a window with text fields for them to input the information.

when they click ok on that window it runs Video_Bar (e:MouseEvent), wich will store the data they entered

function Video_Bar (e:MouseEvent)

{

...

     VideoArray[Number_Of_Videos][0]=VideoInfoBox.TXTVideoName.text;

     VideoArray[Number_Of_Videos][1]=VideoInfoBox.TXTVideoCaption.text;

...

}

this process is repeated as many times as needed.

VideoArray ends up structed like so:

Video[1] = [Object MC]

Video[1][0] = "Video Name"

Video[1][1] = "Video Caption"

then the questions are entered. I use a similar method of presenting a window where they enter the data and then create a visual reference, and store the data. the QuestionsArray is structed like so:

QuestionArray[1] = [Object MC]

QuestionArray[1][0]: Question

QuestionArray[1][1]: A1

QuestionArray[1][2]: A2

QuestionArray[1][3]: A3

QuestionArray[1][4]: A4

QuestionArray[1][5]: Shuffle Status

QuestionArray[1][6]: Type

QuestionArray[1][7]: Correct Answer

QuestionArray[1][8]: SOP

And this process is repeated as needed, usually about 30-50 questions total.

Now, if the user decides to save and quit so they can return later, I run a series of loops to consolidate the two arrays into 1. The code i presented earlier is the 1st half of that.  Im worried about the code being too much to show, show i tried a picture of it. I can write it out if desired. It runs its loops based on how many videos there are, and how many questions there are and ends up with a structure like so:

InfoArray:

  [0]: Module Name

          [1]: Number of Videos

          [2+]: videos                     //It continues to create the video information for how ever many videos there are. if there are 3 videos then in will create the videos in slots [2]. [3], and [4].

          [2+][0]: Video Name

          [2+][1]: Video Caption

          [[1]+1]: Number of questions                    //This information must be stored in the slot after the last video, so using the the information stored in InfoArray[1] i add to it to find where the next empty slot is.

          [[1]+2]: Number of questions selected    

          [=>[1]+3,=<[1+1]][0]: Question                   //during the loop it makes sure that i is greater than or equal to the number of videos +3 s othat the question info is placed after the video info.

          [=>[1]+3,=<[1+1]][1]: Answer 1

          [=>[1]+3,=<[1+1]][2]: Answer 2                //I use the number of videos to find the next slot, in hindsight i could probably come up with a simpler method using .push()

          [=>[1]+3,=<[1+1]][3]: Answer 3

          [=>[1]+3,=<[1+1]][4]: Answer 4

          [=>[1]+3,=<[1+1]][5]: Shuffle Status

          [=>[1]+3,=<[1+1]][6]: Question Type

          [=>[1]+3,=<[1+1]][7]: SOP

          [=>[1]+3,=<[1+1]][8]: Correct Answer

Compile Info.png

InfoArray is then saved using the ByteArray method i mentioned earlier in this post.

When i load, i have InfoArray = BA.readUTF(); in the proper sequence to get all the data into the correct slots of InfoArray.

I am actually having another issue similar to my original now,

When i am moving my data from InfoArray into my VideoArray i am using a loop to set VideoArray[1][0] and VideoArray[1][1] to equal InfoArray[2][0] and InfoArray[2][1]

I get the same error as before in this scenario:

i=1

k=i+1

trace(InfoArray[2]); // output: V1,V1C1

trace(InfoArray[2][0]); <<It errors here

trace(infoArray[2][1]); 

VideoArray[0] = InfoArray[0]

VideoArray[1] = InfoArray[1]

Im not sure why it errors with "Error #1069: Property 0 not found on String and there is no default value." i ran a test:

  myArray[1] = [];

          myArray[1][0] = "spot 1, 0";

          myArray[1][1] = "spot 1, 1";

          myArray2[1] = myArray[1];

          trace("myArray2 = "+myArray2);                  

          trace("myArray2[1][0] = "+myArray2[1][0]);

          trace("myArray2[1][1] = "+myArray2[1][1]);

this test seems the same as my scenario to me, yet it doesnt error out.

Again my apologies for this being so large, i wanted to try and explain as well as possible.

thanks for the help

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