[Flashcoders] adjusting postion of dynamically loaded images
hello everyone i am trying to set x positions of different images which are being dynamically loaded depending upon their width i m writting this code in a for loop imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener (Event.COMPLETE, imgLoaded); trace(width = + imageLoader[i].width); function imgLoaded (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } but width comes out to be zero .. help is needed waiting for your response -- -- -- Thanking You, Pankaj Kumar Singh, 2nd Year Undergraduate Student, Department of Agricultural and Food Engineering, Indian Institute of Technology, Kharagpur Mobile - (+91) 8001231685 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
You should listen for the INIT event, not the COMPLETE one - the images won't have a width until they are initialised. Glen On 01/07/2010 13:50, Pankaj Singh wrote: hello everyone i am trying to set x positions of different images which are being dynamically loaded depending upon their width i m writting this code in a for loop imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener (Event.COMPLETE, imgLoaded); trace(width = + imageLoader[i].width); function imgLoaded (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } but width comes out to be zero .. help is needed waiting for your response ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
even after using INIT i m getting 0 width because event listener function is never called (trace statement is not working) for (var i:int=0; i lettersCount; i++) { imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener(Event.INIT, imgInitialised); trace(width = + imageLoader[i].width); function imgInitialised (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hi all, I'm creating a simple class that has an method that will receive an array as a parameter and store it inside the class in a property. This gives me the error below and I'm stuck. Also I would like to know why if I change the code inside the method setGabarito to just ( aRespGabarito = p1 ) it works... TypeError: Error #1009: Cannot access a property or method of a null object reference. at trueFalse/setGabarito() at tf_teste_fla::MainTimeline/frame1() this is the class: package { import flash.display.Sprite; public class trueFalse extends Sprite{ //propriedades var nome:String; var aRespGabarito:Array; //tera o gabarito do exercicio //construtor public function trueFalse(p1:String) { nome = p1; } public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { var data:Array = p1[r]; aRespGabarito[0] = data; -- ERROR HERE trace(aRespGabarito[0]); } } } } and this is the code inside the test movie: var usuario:trueFalse = new trueFalse(aa); var arrQuestao:Array = new Array(); arrQuestao[0] = [btV1,btX1,btV1,0]; arrQuestao[1] = [btV2,btX2,btX2,0]; arrQuestao[2] = [btV3,btX3,btX3,0]; usuario.setGabarito(arrQuestao); thanks for any help, rodrigo. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
Try it in the second trace you have; it's not loaded When you're first tracing Sent from my iPhone On Jul 1, 2010, at 6:32 AM, Pankaj Singh singh.pankaj.iitkg...@gmail.com wrote: even after using INIT i m getting 0 width because event listener function is never called (trace statement is not working) for (var i:int=0; i lettersCount; i++) { imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener(Event.INIT, imgInitialised); trace(width = + imageLoader[i].width); function imgInitialised (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
Hi, Are you storing your loaders somewhere outside the function - e.g. is imageLoader an array outside the function? If not, your loaders may go out of scope... Also, your function imgInitialised may go out of scope because that is declared inside the loop - not 100% about this, but try putting imgInitialised outside your function that creates the loaders. e.g. pseudo code: var imageLoader:Array; function loadImages() { for(i = 0 to lettersCount) { startLoading addEventListener } } function imgInitialised(e:Event):void { //hello from imgInitialised. } HTH Glen On 01/07/2010 14:32, Pankaj Singh wrote: even after using INIT i m getting 0 width because event listener function is never called (trace statement is not working) for (var i:int=0; i lettersCount; i++) { imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener(Event.INIT, imgInitialised); trace(width = + imageLoader[i].width); function imgInitialised (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
Hi, Oops, missed one - try calling load() after you added the listener... Glen On 01/07/2010 14:32, Pankaj Singh wrote: even after using INIT i m getting 0 width because event listener function is never called (trace statement is not working) for (var i:int=0; i lettersCount; i++) { imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener(Event.INIT, imgInitialised); trace(width = + imageLoader[i].width); function imgInitialised (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference.
Data is an Array and p is a String -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: donderdag 1 juli 2010 15:36 To: Flash Coders List Subject: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Hi all, I'm creating a simple class that has an method that will receive an array as a parameter and store it inside the class in a property. This gives me the error below and I'm stuck. Also I would like to know why if I change the code inside the method setGabarito to just ( aRespGabarito = p1 ) it works... TypeError: Error #1009: Cannot access a property or method of a null object reference. at trueFalse/setGabarito() at tf_teste_fla::MainTimeline/frame1() this is the class: package { import flash.display.Sprite; public class trueFalse extends Sprite{ //propriedades var nome:String; var aRespGabarito:Array; //tera o gabarito do exercicio //construtor public function trueFalse(p1:String) { nome = p1; } public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { var data:Array = p1[r]; aRespGabarito[0] = data; -- ERROR HERE trace(aRespGabarito[0]); } } } } and this is the code inside the test movie: var usuario:trueFalse = new trueFalse(aa); var arrQuestao:Array = new Array(); arrQuestao[0] = [btV1,btX1,btV1,0]; arrQuestao[1] = [btV2,btX2,btX2,0]; arrQuestao[2] = [btV3,btX3,btX3,0]; usuario.setGabarito(arrQuestao); thanks for any help, rodrigo. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Geen virus gevonden in het binnenkomende-bericht. Gecontroleerd door AVG - www.avg.com Versie: 9.0.830 / Virusdatabase: 271.1.1/2974 - datum van uitgifte: 06/30/10 20:38:00 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference.
thanks for your reply cor, you are correct, p1 is a parameter for the constructor (as string) and for the method (as array). Still, if i change the datatype of data to string the error persists public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. var data:String; //copia os membros do array for (var r = 0; r = tamanho; r++ ) { data = p1[r]; //data = hello; aRespGabarito[r] = data; -any of the declarations above for data results in an error. } } - Original Message - From: Cor c...@chello.nl To: 'Rodrigo Augusto Guerra' rodr...@alumni.org.br; 'Flash Coders List' flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 10:42 AM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Data is an Array and p is a String -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: donderdag 1 juli 2010 15:36 To: Flash Coders List Subject: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Hi all, I'm creating a simple class that has an method that will receive an array as a parameter and store it inside the class in a property. This gives me the error below and I'm stuck. Also I would like to know why if I change the code inside the method setGabarito to just ( aRespGabarito = p1 ) it works... TypeError: Error #1009: Cannot access a property or method of a null object reference. at trueFalse/setGabarito() at tf_teste_fla::MainTimeline/frame1() this is the class: package { import flash.display.Sprite; public class trueFalse extends Sprite{ //propriedades var nome:String; var aRespGabarito:Array; //tera o gabarito do exercicio //construtor public function trueFalse(p1:String) { nome = p1; } public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { var data:Array = p1[r]; aRespGabarito[0] = data; -- ERROR HERE trace(aRespGabarito[0]); } } } } and this is the code inside the test movie: var usuario:trueFalse = new trueFalse(aa); var arrQuestao:Array = new Array(); arrQuestao[0] = [btV1,btX1,btV1,0]; arrQuestao[1] = [btV2,btX2,btX2,0]; arrQuestao[2] = [btV3,btX3,btX3,0]; usuario.setGabarito(arrQuestao); thanks for any help, rodrigo. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Geen virus gevonden in het binnenkomende-bericht. Gecontroleerd door AVG - www.avg.com Versie: 9.0.830 / Virusdatabase: 271.1.1/2974 - datum van uitgifte: 06/30/10 20:38:00 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference.
thanks david, that did the trick... I also realized that this MUST be done inside the method and not along with the declaration on the top of the class, sorry abt my ignorance but why ? thanks! - Original Message - From: David Hunter To: rodr...@alumni.org.br Sent: Thursday, July 01, 2010 11:45 AM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. are you missing the following?: aRespGabarito = new Array(); From: rodr...@alumni.org.br To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Date: Thu, 1 Jul 2010 11:28:28 -0300 thanks for your reply cor, you are correct, p1 is a parameter for the constructor (as string) and for the method (as array). Still, if i change the datatype of data to string the error persists public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. var data:String; //copia os membros do array for (var r = 0; r = tamanho; r++ ) { data = p1[r]; //data = hello; aRespGabarito[r] = data; -any of the declarations above for data results in an error. } } - Original Message - From: Cor c...@chello.nl To: 'Rodrigo Augusto Guerra' rodr...@alumni.org.br; 'Flash Coders List' flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 10:42 AM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Data is an Array and p is a String -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: donderdag 1 juli 2010 15:36 To: Flash Coders List Subject: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Hi all, I'm creating a simple class that has an method that will receive an array as a parameter and store it inside the class in a property. This gives me the error below and I'm stuck. Also I would like to know why if I change the code inside the method setGabarito to just ( aRespGabarito = p1 ) it works... TypeError: Error #1009: Cannot access a property or method of a null object reference. at trueFalse/setGabarito() at tf_teste_fla::MainTimeline/frame1() this is the class: package { import flash.display.Sprite; public class trueFalse extends Sprite{ //propriedades var nome:String; var aRespGabarito:Array; //tera o gabarito do exercicio //construtor public function trueFalse(p1:String) { nome = p1; } public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { var data:Array = p1[r]; aRespGabarito[0] = data; -- ERROR HERE trace(aRespGabarito[0]); } } } } and this is the code inside the test movie: var usuario:trueFalse = new trueFalse(aa); var arrQuestao:Array = new Array(); arrQuestao[0] = [btV1,btX1,btV1,0]; arrQuestao[1] = [btV2,btX2,btX2,0]; arrQuestao[2] = [btV3,btX3,btX3,0]; usuario.setGabarito(arrQuestao); thanks for any help, rodrigo. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Geen virus gevonden in het binnenkomende-bericht. Gecontroleerd door AVG - www.avg.com Versie: 9.0.830 / Virusdatabase: 271.1.1/2974 - datum van uitgifte: 06/30/10 20:38:00 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- Get a free e-mail account with Hotmail. Sign-up now. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adjusting postion of dynamically loaded images
thanks to everyone my problem has been solved :D On Thu, Jul 1, 2010 at 7:14 PM, Glen Pike g...@engineeredarts.co.uk wrote: Hi, Oops, missed one - try calling load() after you added the listener... Glen On 01/07/2010 14:32, Pankaj Singh wrote: even after using INIT i m getting 0 width because event listener function is never called (trace statement is not working) for (var i:int=0; i lettersCount; i++) { imageLoader[i].load (new URLRequest( xmlLettersList[i].attribute(img))); imageLoader[i].width = imageLoader[i].addEventListener(Event.INIT, imgInitialised); trace(width = + imageLoader[i].width); function imgInitialised (e:Event):Number { var bm:Bitmap = Bitmap(e.target.content); trace(inside function image Loaded); return bm.width; } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- -- -- Thanking You, Pankaj Kumar Singh, 2nd Year Undergraduate Student, Department of Agricultural and Food Engineering, Indian Institute of Technology, Kharagpur Mobile - (+91) 8001231685 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference.
From your loop, you're accessing an array element that doesn't exist. I would actually advise a different approach to the problem. Don't use pure arrays within pure arrays (called multidimensional arrays). I find it very hard to understand and maintain that code. It can get confusing easily and doesn't easily allow for scalability. I would have an array store class instances which are just classes with public properties only (called value objects or VOs). One or more of those properties of the VO instance can be an array, so you can have nested logic and data, but you are effectively using an object array object array structure, where the objects are defined by you, the class-writer, instead of an array array array structure where you have to do crazy ways to access the data. By using value object instances, you are describing the data and structure. By using only arrays within arrays, and no objects, you have neither structure definition or data definition. When you loop through an array, instead of this approach: var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { data = p1[r]; Assuming you create an array of class instances, I would recommend this instead for simplicity's sake because I think the problem is the way you are looping through the array: var questionVO1:QuestionVO = new QuestionVO(); questionVO.question = Which fruit is yellow?; questionVO.answer = Banana; var questionVO2:QuestionVO = new QuestionVO(); questionVO2.question = What color is the sky?; questionVO2.answer = Blue; var myQuestions:Array = [questionVO1, questionVO2]; //So alternatively (not knowing exactly what you wrote your loop for), as an example, you can //loop through myQuestions and set all the VO's score property to 0, like this: for each (var questionVO:QuestionVO in myQuestions) { //set any property of each questionVO here questionVO.score = 0; } //etc. I'd actually store the question information in XML and loop through that to create these VO instances, but you get the point. //So to check to see if the answer is right: if(userResponseTextField1.text == questionVO1.answer) { questionVO.score++; } I'd actually take a more elegant approach than that for a quiz, but this just shows you the basic form of how to check for the user's right response. Jason Merrill Instructional Technology Architect Bank of America Global Learning Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (Note: these resources are only available for Bank of America associates) -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: Thursday, July 01, 2010 10:28 AM To: 'Flash Coders List' Subject: Re: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. thanks for your reply cor, you are correct, p1 is a parameter for the constructor (as string) and for the method (as array). Still, if i change the datatype of data to string the error persists public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. var data:String; //copia os membros do array for (var r = 0; r = tamanho; r++ ) { data = p1[r]; //data = hello; aRespGabarito[r] = data; -any of the declarations above for data results in an error. } } - Original Message - From: Cor c...@chello.nl To: 'Rodrigo Augusto Guerra' rodr...@alumni.org.br; 'Flash Coders List' flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 10:42 AM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Data is an Array and p is a String -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: donderdag 1 juli 2010 15:36 To: Flash Coders List Subject: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Hi all, I'm creating a simple class that has an method that will receive an array as a parameter and store it inside the class in a property. This gives me the error below and I'm stuck. Also I would like to know why if I change the code inside the method setGabarito to just ( aRespGabarito = p1 ) it works... TypeError: Error #1009: Cannot access a property or method of a null object reference. at trueFalse/setGabarito() at tf_teste_fla::MainTimeline/frame1() this is the class: package { import flash.display.Sprite; public class trueFalse extends Sprite{ //propriedades var
Re: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference.
Thanks for your insights Jason. At this moment I'm migrating some AS2 code to AS3 OOP, and as seen, I'm not that familiar with OOP, that´s why these directions are *VERY* helpfull welcome. thanks. - Original Message - From: Merrill, Jason jason.merr...@bankofamerica.com To: Rodrigo Augusto Guerra rodr...@alumni.org.br; Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 12:22 PM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. From your loop, you're accessing an array element that doesn't exist. I would actually advise a different approach to the problem. Don't use pure arrays within pure arrays (called multidimensional arrays). I find it very hard to understand and maintain that code. It can get confusing easily and doesn't easily allow for scalability. I would have an array store class instances which are just classes with public properties only (called value objects or VOs). One or more of those properties of the VO instance can be an array, so you can have nested logic and data, but you are effectively using an object array object array structure, where the objects are defined by you, the class-writer, instead of an array array array structure where you have to do crazy ways to access the data. By using value object instances, you are describing the data and structure. By using only arrays within arrays, and no objects, you have neither structure definition or data definition. When you loop through an array, instead of this approach: var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { data = p1[r]; Assuming you create an array of class instances, I would recommend this instead for simplicity's sake because I think the problem is the way you are looping through the array: var questionVO1:QuestionVO = new QuestionVO(); questionVO.question = Which fruit is yellow?; questionVO.answer = Banana; var questionVO2:QuestionVO = new QuestionVO(); questionVO2.question = What color is the sky?; questionVO2.answer = Blue; var myQuestions:Array = [questionVO1, questionVO2]; //So alternatively (not knowing exactly what you wrote your loop for), as an example, you can //loop through myQuestions and set all the VO's score property to 0, like this: for each (var questionVO:QuestionVO in myQuestions) { //set any property of each questionVO here questionVO.score = 0; } //etc. I'd actually store the question information in XML and loop through that to create these VO instances, but you get the point. //So to check to see if the answer is right: if(userResponseTextField1.text == questionVO1.answer) { questionVO.score++; } I'd actually take a more elegant approach than that for a quiz, but this just shows you the basic form of how to check for the user's right response. Jason Merrill Instructional Technology Architect Bank of America Global Learning Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (Note: these resources are only available for Bank of America associates) -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: Thursday, July 01, 2010 10:28 AM To: 'Flash Coders List' Subject: Re: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. thanks for your reply cor, you are correct, p1 is a parameter for the constructor (as string) and for the method (as array). Still, if i change the datatype of data to string the error persists public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. var data:String; //copia os membros do array for (var r = 0; r = tamanho; r++ ) { data = p1[r]; //data = hello; aRespGabarito[r] = data; -any of the declarations above for data results in an error. } } - Original Message - From: Cor c...@chello.nl To: 'Rodrigo Augusto Guerra' rodr...@alumni.org.br; 'Flash Coders List' flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 10:42 AM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Data is an Array and p is a String -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: donderdag 1 juli 2010 15:36 To: Flash Coders List Subject: [Flashcoders] passing an array as a method = TypeError: Error #1009: Cannot access a property or method of a null object reference. Hi all, I'm creating a simple class that has an method that will receive an array as a
RE: [Flashcoders] passing an array as a method = TypeError:Error#1009: Cannot access a property or method of a null object reference.
Sure. This is anAS3 example, but you can still do the same thing with VOs in AS2 as well. Jason Merrill Instructional Technology Architect Bank of America Global Learning Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (Note: these resources are only available for Bank of America associates) -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: Thursday, July 01, 2010 12:11 PM To: Flash Coders List Subject: Re: [Flashcoders] passing an array as a method = TypeError:Error#1009: Cannot access a property or method of a null object reference. Thanks for your insights Jason. At this moment I'm migrating some AS2 code to AS3 OOP, and as seen, I'm not that familiar with OOP, that´s why these directions are *VERY* helpfull welcome. thanks. - Original Message - From: Merrill, Jason jason.merr...@bankofamerica.com To: Rodrigo Augusto Guerra rodr...@alumni.org.br; Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Thursday, July 01, 2010 12:22 PM Subject: RE: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. From your loop, you're accessing an array element that doesn't exist. I would actually advise a different approach to the problem. Don't use pure arrays within pure arrays (called multidimensional arrays). I find it very hard to understand and maintain that code. It can get confusing easily and doesn't easily allow for scalability. I would have an array store class instances which are just classes with public properties only (called value objects or VOs). One or more of those properties of the VO instance can be an array, so you can have nested logic and data, but you are effectively using an object array object array structure, where the objects are defined by you, the class-writer, instead of an array array array structure where you have to do crazy ways to access the data. By using value object instances, you are describing the data and structure. By using only arrays within arrays, and no objects, you have neither structure definition or data definition. When you loop through an array, instead of this approach: var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. for (var r = 0; r = tamanho; r++ ) { data = p1[r]; Assuming you create an array of class instances, I would recommend this instead for simplicity's sake because I think the problem is the way you are looping through the array: var questionVO1:QuestionVO = new QuestionVO(); questionVO.question = Which fruit is yellow?; questionVO.answer = Banana; var questionVO2:QuestionVO = new QuestionVO(); questionVO2.question = What color is the sky?; questionVO2.answer = Blue; var myQuestions:Array = [questionVO1, questionVO2]; //So alternatively (not knowing exactly what you wrote your loop for), as an example, you can //loop through myQuestions and set all the VO's score property to 0, like this: for each (var questionVO:QuestionVO in myQuestions) { //set any property of each questionVO here questionVO.score = 0; } //etc. I'd actually store the question information in XML and loop through that to create these VO instances, but you get the point. //So to check to see if the answer is right: if(userResponseTextField1.text == questionVO1.answer) { questionVO.score++; } I'd actually take a more elegant approach than that for a quiz, but this just shows you the basic form of how to check for the user's right response. Jason Merrill Instructional Technology Architect Bank of America Global Learning Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (Note: these resources are only available for Bank of America associates) -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Rodrigo Augusto Guerra Sent: Thursday, July 01, 2010 10:28 AM To: 'Flash Coders List' Subject: Re: [Flashcoders] passing an array as a method = TypeError: Error#1009: Cannot access a property or method of a null object reference. thanks for your reply cor, you are correct, p1 is a parameter for the constructor (as string) and for the method (as array). Still, if i change the datatype of data to string the error persists public function setGabarito(p1:Array) { var tamanho = p1.length - 1 // o indice comeca com zero entao tem 1 elemento a menos. var data:String; //copia os membros do array for (var r = 0; r = tamanho; r++ ) { data = p1[r]; //data = hello; aRespGabarito[r] = data; -any of the declarations above for data results in an error. } } - Original Message -