Comunidad de diseño web y desarrollo en internet online

TypeError: Error #1009

Citar            
MensajeEscrito el 24 Ago 2011 08:00 pm
Hola a todos. Soy novata en el foro y en actionscript también y necesito vuestra ayuda. Estoy diseñando un juego didáctico en As3 con Adobe Flash. El juego tendrá varias escenas, pero aún estoy en la primera. La escena tiene varios botones cada cual lleva a otro apartado con sus páginas (o pantallas) correspondientes. Utilizo para todos los fotogramas claves el actionscript en la línea de tiempo principal (main timeline). Ahora quiero poner una serie de pantallas en donde el estudiante pueda agarrrar y arrastrar (drag and drop) los simbolos a sus sitios correspondientes.
Probé primero con un archivo con un único fotograma y el actionscript para ver si funciona el juego y todo bien. Entonces intenté ampliar el juego añadiendo otro fotograma para saltar a otra pantalla de drag and drop. Inserté el código en el nuevo fotograma clave en la línea de actionscript y modifiqué el código donde fuese necesario.
Pero ahora me pasa algo muy raro: cuando pruebo la pelicula en flash, puedo jugar el juego del primer fotograma clave sin problema, pero cuando salto al segundo fotograma (a la segunda pantalla), aparecen los simbolos arrastrados en el 1er fotograma también en el 2o y además se pueden arrastrar. Y lo mismo viceversa, es decir, cuando vuelvo mediante un botón al 1er fotograma, me aparecen los símbolos arrastrados del 2o fotograma.
El error que me da es:
TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo.
at draganddroparabe_fla::MainTimeline/mdown()
TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo.
at draganddroparabe_fla::MainTimeline/mUp()

Me volví prácticamente loca, modifiqué un montón de cosas para ver si podía solucionarlo yo sola pero he llegado a un punto que no sé qué más hacer. Y no entiendo cómo pueden ser visibles los símbolos.

Sospecho que el problema reside en el siguiente código (capaz que tenga que insertar alguna cosa):

Fotograma 1

Código ActionScript :

//---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);
               
         }
}


Fotograma 2

Código ActionScript :

//---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);
               
         }
}


Bueno, no sé si me he explicado bien (si no, díganmelo). Es que todo es muy nuevo para mí y voy aprendiendo sobre la marcha con problemas así. Espero que haya alguien que pueda echarme una mano. Quizás prefieran ver todo el código, por sí acaso (espero que no importa):

FOTOGRAMA 1

Código ActionScript :

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);
      }
   }
}

¿Qué puedo hacer?
Un saludo,
Enteka

Por enteka

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 25 Ago 2011 01:45 pm
Hola, me han respondido en otro foro y me estoy acercando.

ned murphy escribió:

El error 1009 indica que uno de los objetos que están siendo dirigidos por el código está fuera de alcance. Esto podría significar que el objeto ....

- no está en la lista de visualización (display list)
- no tiene un nombre de instancia (o el nombre de la instancia está mal escrito)
- no existe en el fotograma en el que el código está tratando de hablar con él
- es animado en su lugar, pero no tiene asignignados los nombres de instancia en todos los fotogramas clave
- es uno de dos o más fotogramas clave consecutivos de los mismos objetos sin nombre asignado en el fotograma anterior.

Si entra en la sección Configuración de publicación Flash y selecciona la opción permitir la depuración, el mensaje de error debe tener un número de línea que sigue al número del fotograma que le ayudará a identificar de qué objeto se trata.

Así encontré los objetos que me daban error: response_mc y response2_mc

Ejemplo:


Código ActionScript :

function mdown(e:MouseEvent):void { 
      e.currentTarget.startDrag(); 
      setChildIndex(MovieClip(e.currentTarget), numChildren - 1); 
     response_mc.gotoAndStop(1);


Supongo que tendría que referirme a este objeto antes, es decir, introducirlo en el código.
Por ahora, borré estos símboles y ya no me da error, pero sigo con el mismo problema:
cuando pruebo la peli, los elementos arrastrados del 2o fotograma se ven en el primero y vice versa. Además el jugador puede arrastrarlos.
¿Alguna idea?

Por enteka

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 25 Ago 2011 03:52 pm
Hola Enteka, los MovieClips los estas colocando en el escenario dinamicamente? Por que no los ocultas al pasar al siguiente fotograma?

Saludos!

Por cadaop

8 de clabLevel



 

safari

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.