TypeError: Error #1009

  • enteka
  • Born
  • Born
  • enteka
  • Posts: 1

Post 3+ Months Ago

Why I get the message in English?I wrote it in Spanish...

Hello everyone. I am novice in the Forum and actionscript also and I need your help. I am designing didactic game in As3 with Adobe Flash. The game will have several scenes, but I am still in the first. The scene has several buttons each of which leads to another section with your pages (or screens) relevant. The actionscript I use for all the key frames in the main timeline (main timeline). Now I want to put a series of screens where the student can agarrrar and drag (drag and drop) the characters to their corresponding websites.
I first tried to file with a unique frame and the actionscript to see if works for the game and everything. I then tried to expand the game by adding another frame to jump to another screen of drag and drop. I inserté the code in the new keyframe in the line of actionscript and I modified the code where necessary.
But now I feel something very weird: when I test the movie in flash, I can play the game of the first keyframe without problem, but when I jump to the second frame (to the second screen), appear the symbols drawn on the 1st frame also in the 2nd and in addition you can drag. And the same vice versa, i.e. when I come back using a button to the 1st frame, get me dragged symbols of the second frame.
The error I get is:
TypeError: Error #1009: it cannot access a property or a method of a reference to a null object.
(at draganddroparabe_fla: MainTimeline/mdown)
TypeError: Error #1009: it cannot access a property or a method of a reference to a null object.
(at draganddroparabe_fla: MainTimeline/mUp)

I went nearly mad, I modified a lot of things to see if I could fix it myself but I have come to a point that I do not know what else to do. And I do not understand how symbols can be visible.

I suspect that the problem lies in the following code (able to you have to insert something):

Frame 1

Code:
Code: [ Select ]
//---función del fotograma 1---\

function mdown(e:MouseEvent):void {
   e.currentTarget.startDrag();
   setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
   response_mc.gotoAndStop(1);
}
function mUp(e:MouseEvent):void {
     var dropIndex:int = dropArray.indexOf(e.currentTarget);
     var target:MovieClip = e.currentTarget as MovieClip;
         
     target.stopDrag();

     if (target.hitTestObject(hitArray[dropIndex])) {
          target.x = hitArray[dropIndex].x;
          target.y = hitArray[dropIndex].y;
        playSound(SoundId);
        response_mc.gotoAndStop(2);
     }else{
          target.x = positionsArray[dropIndex].xPos;
          target.y = positionsArray[dropIndex].yPos;
        playSound(SoundId2);
        response_mc.gotoAndStop(3);
        
     }
}
  1. //---función del fotograma 1---\
  2. function mdown(e:MouseEvent):void {
  3.    e.currentTarget.startDrag();
  4.    setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
  5.    response_mc.gotoAndStop(1);
  6. }
  7. function mUp(e:MouseEvent):void {
  8.      var dropIndex:int = dropArray.indexOf(e.currentTarget);
  9.      var target:MovieClip = e.currentTarget as MovieClip;
  10.          
  11.      target.stopDrag();
  12.      if (target.hitTestObject(hitArray[dropIndex])) {
  13.           target.x = hitArray[dropIndex].x;
  14.           target.y = hitArray[dropIndex].y;
  15.         playSound(SoundId);
  16.         response_mc.gotoAndStop(2);
  17.      }else{
  18.           target.x = positionsArray[dropIndex].xPos;
  19.           target.y = positionsArray[dropIndex].yPos;
  20.         playSound(SoundId2);
  21.         response_mc.gotoAndStop(3);
  22.         
  23.      }
  24. }




Frame 2

Code:
Code: [ Select ]
//---parte del fotograma 2---\

function mdown1(a:MouseEvent):void {
   a.currentTarget.startDrag();
   setChildIndex(MovieClip(a.currentTarget), numChildren - 1);
   response2_mc.gotoAndStop(1);
}
function mUp1(a:MouseEvent):void {
     var dropIndex2:int = dropArray2.indexOf(a.currentTarget);
     var target2:MovieClip = a.currentTarget as MovieClip;
         
     target2.stopDrag();

     if (target2.hitTestObject(hitArray2[dropIndex2])) {
          target2.x = hitArray2[dropIndex2].x;
          target2.y = hitArray2[dropIndex2].y;
        playSound3(SoundId3);
        response2_mc.gotoAndStop(2);
     }else{
          target2.x = positionsArray2[dropIndex2].xPos;
          target2.y = positionsArray2[dropIndex2].yPos;
        playSound4(SoundId4);
        response2_mc.gotoAndStop(3);
        
     }
}
  1. //---parte del fotograma 2---\
  2. function mdown1(a:MouseEvent):void {
  3.    a.currentTarget.startDrag();
  4.    setChildIndex(MovieClip(a.currentTarget), numChildren - 1);
  5.    response2_mc.gotoAndStop(1);
  6. }
  7. function mUp1(a:MouseEvent):void {
  8.      var dropIndex2:int = dropArray2.indexOf(a.currentTarget);
  9.      var target2:MovieClip = a.currentTarget as MovieClip;
  10.          
  11.      target2.stopDrag();
  12.      if (target2.hitTestObject(hitArray2[dropIndex2])) {
  13.           target2.x = hitArray2[dropIndex2].x;
  14.           target2.y = hitArray2[dropIndex2].y;
  15.         playSound3(SoundId3);
  16.         response2_mc.gotoAndStop(2);
  17.      }else{
  18.           target2.x = positionsArray2[dropIndex2].xPos;
  19.           target2.y = positionsArray2[dropIndex2].yPos;
  20.         playSound4(SoundId4);
  21.         response2_mc.gotoAndStop(3);
  22.         
  23.      }
  24. }




Well, I do not know if I explained good (if not, tell me). It is that everything is very new for me and Im learning on the fly with problems as well. I hope that someone who can lend me a hand. They might prefer to see all the code, itself perhaps (I hope that it does not matter):

FRAME 1

Code:

Code: [ Select ]
stop();
next1.addEventListener(MouseEvent.CLICK,clickNext1);
function clickNext1(event:MouseEvent):void
{
  gotoAndStop("getPagina2");
}

//Array to hold the target instances, the drop instances,
//and the start positions of the drop instances.
var score:Number = 0;
var hitArray:Array = new Array(hitTarget1,hitTarget2,hitTarget3,hitTarget4);
var dropArray:Array = new Array(drop1,drop2,drop3,drop4);
var positionsArray:Array = new Array();


//This adds the mouse down and up listener to the drop instances
//and add the starting x and y positions of the drop instances
//into the array.
for (var i:int = 0; i < dropArray.length; i++) {
     dropArray[i].buttonMode = true;
     dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
     dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
         
     positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}

//This drags the object that has been selected and moves it
//to the top of the display list. This means you can't drag
//this object underneath anything.
function mdown(e:MouseEvent):void {
   e.currentTarget.startDrag();
   setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
   response_mc.gotoAndStop(1);
}

//This stops the dragging of the selected object when the mouse is
//released. If the object is dropped on the corresponding target
//then it get set to the x and y position of the target. Otherwise
//it returns to the original position.
function mUp(e:MouseEvent):void {
     var dropIndex:int = dropArray.indexOf(e.currentTarget);
     var target:MovieClip = e.currentTarget as MovieClip;
         
     target.stopDrag();

     if (target.hitTestObject(hitArray[dropIndex])) {
          target.x = hitArray[dropIndex].x;
          target.y = hitArray[dropIndex].y;
        playSound(SoundId);
        response_mc.gotoAndStop(2);
     }else{
          target.x = positionsArray[dropIndex].xPos;
          target.y = positionsArray[dropIndex].yPos;
        playSound(SoundId2);
        response_mc.gotoAndStop(3);
        
     }
}
function playSound(SoundId:Class):void{
      var sound = new SoundId();
      var channel:SoundChannel = sound.play();
}
function playSound2(SoundId2:Class):void{
      var sound = new SoundId2();
      var channel:SoundChannel = sound.play();
}

reset.addEventListener(MouseEvent.CLICK, backObjects);

function backObjects(e:MouseEvent):void{
 for(var i:int = 0; i < dropArray.length; i++){
   if(dropArray[i].x == hitArray[i].x && dropArray[i].y == hitArray[i].y){
     dropArray[i].x = positionsArray[i].xPos;
     dropArray[i].y = positionsArray[i].yPos;
    response_mc.gotoAndStop(1);
   }
  }
}
  1. stop();
  2. next1.addEventListener(MouseEvent.CLICK,clickNext1);
  3. function clickNext1(event:MouseEvent):void
  4. {
  5.   gotoAndStop("getPagina2");
  6. }
  7. //Array to hold the target instances, the drop instances,
  8. //and the start positions of the drop instances.
  9. var score:Number = 0;
  10. var hitArray:Array = new Array(hitTarget1,hitTarget2,hitTarget3,hitTarget4);
  11. var dropArray:Array = new Array(drop1,drop2,drop3,drop4);
  12. var positionsArray:Array = new Array();
  13. //This adds the mouse down and up listener to the drop instances
  14. //and add the starting x and y positions of the drop instances
  15. //into the array.
  16. for (var i:int = 0; i < dropArray.length; i++) {
  17.      dropArray[i].buttonMode = true;
  18.      dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
  19.      dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
  20.          
  21.      positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
  22. }
  23. //This drags the object that has been selected and moves it
  24. //to the top of the display list. This means you can't drag
  25. //this object underneath anything.
  26. function mdown(e:MouseEvent):void {
  27.    e.currentTarget.startDrag();
  28.    setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
  29.    response_mc.gotoAndStop(1);
  30. }
  31. //This stops the dragging of the selected object when the mouse is
  32. //released. If the object is dropped on the corresponding target
  33. //then it get set to the x and y position of the target. Otherwise
  34. //it returns to the original position.
  35. function mUp(e:MouseEvent):void {
  36.      var dropIndex:int = dropArray.indexOf(e.currentTarget);
  37.      var target:MovieClip = e.currentTarget as MovieClip;
  38.          
  39.      target.stopDrag();
  40.      if (target.hitTestObject(hitArray[dropIndex])) {
  41.           target.x = hitArray[dropIndex].x;
  42.           target.y = hitArray[dropIndex].y;
  43.         playSound(SoundId);
  44.         response_mc.gotoAndStop(2);
  45.      }else{
  46.           target.x = positionsArray[dropIndex].xPos;
  47.           target.y = positionsArray[dropIndex].yPos;
  48.         playSound(SoundId2);
  49.         response_mc.gotoAndStop(3);
  50.         
  51.      }
  52. }
  53. function playSound(SoundId:Class):void{
  54.       var sound = new SoundId();
  55.       var channel:SoundChannel = sound.play();
  56. }
  57. function playSound2(SoundId2:Class):void{
  58.       var sound = new SoundId2();
  59.       var channel:SoundChannel = sound.play();
  60. }
  61. reset.addEventListener(MouseEvent.CLICK, backObjects);
  62. function backObjects(e:MouseEvent):void{
  63.  for(var i:int = 0; i < dropArray.length; i++){
  64.    if(dropArray[i].x == hitArray[i].x && dropArray[i].y == hitArray[i].y){
  65.      dropArray[i].x = positionsArray[i].xPos;
  66.      dropArray[i].y = positionsArray[i].yPos;
  67.     response_mc.gotoAndStop(1);
  68.    }
  69.   }
  70. }



What can I do?
Greetings,
Enteka
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.