Skip to main content
backdes
Participant
July 2, 2009
Answered

after make a puzzle i need that goto.. to another frame?

  • July 2, 2009
  • 1 reply
  • 973 views

estoy haciendo una aplicacion tipo puzzle pero necesito que al organizar las fichas me envie a otro frame donde se carge un puzzle distinto

el codigo que estoy usando es:

////////////////////////////////////////////////////////////////////////////////////
//VARIABLES

//Esta variable almacena el resultado del juego.
var correcto:Boolean = false;
//Almacena todos los clips de arrastre
var clips:Array = [drag1,drag2,drag3,drag4,drag5,drag6];
//Almacena los nombres de los clips de destino para los clips de arrastre
var destinos:Array = [hit1,hit2,hit3,hit4,hit5,hit6];


////////////////////////////////////////////////////////////////////////////////////
//FUNCIONES

//Función que se ejecuta al inicio y programa la escena
function Empezar(){
        GuardarDatos();
        ProgramarArrastres();
        Corregir();
}

//Almacena los datos iniciales de los clips de arrastre como variables dentro de cada clip.
//Estos datos se utilizan despues para ver si se ha dejado sobre el destino, o para colocarlos de nuevo
//en su posición inicial
function GuardarDatos(){
        for (var i = 0;i < clips.length; i++){
                clips.xIni = clips._x;
                clips.yIni = clips._y;
                clips.destino = destinos;
                clips.prof = clips.getDepth();
        }
}

//Programa los clips de arrastre, añadiendo a cada uno los eventos onPress y onRelease
function ProgramarArrastres(){
        for(var i = 0; i < clips.length; i++){
                var clip = clips;
                clip.onPress = function(){
                        startDrag(this,false);
                        this.swapDepths(getNextHighestDepth());
                }
                clip.onRelease = function(){
                        Soltar(this);
                        this.swapDepths(this.prof);
                }
        }
}

//Esta función se ejecuta cuando se reproduce el evento onPress de alguno de los clips de
//arrastre. Comprueba si el clip de arrastre está sobre su clip de destino, y si es así, lo
//coloca en la misma posición que este. Si no, lo devuelve a la posición inicial que se ha
//almacenado al principio.
function Soltar(clip){
        clip.stopDrag();
        if(clip.hitTest(clip.destino)){
                clip._x = clip.destino._x;
                clip._y = clip.destino._y;
        }else{
                clip._x = clip.xIni;
                clip._y = clip.yIni;
        }
        Corregir();
}

//Corrige el juego. Recorre todos los clips de arrastre y ve si están colocados
//o no. Modifica los valores de los campos de texto Resuelto_txt y Aciertos_txt
//para mostrar los datos del juego.
function Corregir(){
        var aciertos = 0;
        for(var i = 0; i < clips.length; i++){
                if(clips.hitTest(destinos)){
                        aciertos++;
                }
        }
        correcto = (aciertos == clips.length)?true:false;
        Resuelto_txt.text = correcto;
        Aciertos_txt.text = aciertos;
}

//Empezamos
Empezar();

Gracias
stop();

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

thanks ypu helpme a lot

but the code works better like this

function Corregir(){
        var aciertos = 0;
        for(var i = 0; i < clips.length; i++){
                if(clips.hitTest(destinos)){
                        aciertos++;
               
           if (corregir=true){
           this.nextFrame();
           
      }
    }
  }
}

but your help was very important.


I don't see how that can work better because it is not correctly coded.  When using an "if" to compare things, you need to use ==.

= is to assign a value to something whereas == is to compare something.

Secondly, unless you created some new variable that you aren't showing, there is no "corregir" variable, just the function

1 reply

Ned Murphy
Legend
July 2, 2009

Hablo espanol un poco solamente.  Cuando quere goto another frame.... correcto = true?

backdes
backdesAuthor
Participant
July 2, 2009

I'm doing a puzzle-type applications but I need to arrange the cards I send to another frame where it loads a different puzzle 

the code I'm using is:

Im think i have tu create a new variable and use if, but i dont know where it have be used

Ned Murphy
Legend
July 2, 2009

I don't know what you mean when you say "arrange the cards I send to another frame"... but if I had to guess I'd say it might have been intended to say... "arrange the cards before I send to another frame"  If my guess is correct then I think you can use something like...

function Corregir(){
        var aciertos = 0;
        for(var i = 0; i < clips.length; i++){
                if(clips.hitTest(destinos)){
                        aciertos++;
                }
        }
        correcto = (aciertos == clips.length)?true:false;
        Resuelto_txt.text = correcto;
        Aciertos_txt.text = aciertos;
       
        if(correcto){
              gotoAndPlay(???);    // ??? is the number or label of the other frame
        }
}

From what I can make of the code, correcto will only be true if all clips are aciertos