Comunidad de diseño web y desarrollo en internet online

[Ayuda] Exportar Imagen para Actionscript

Citar            
MensajeEscrito el 14 Ene 2010 09:36 pm
Hola gente, bueno estaba siguiendo el tutorial de Teseo sobre rompecabezas. Y se me presento una dificultad. Cuando muevo el puzzle al segundo fotograma la imagen vinculada desde librería se muestra en el primero, eso lo entiendo porque Teseo pidió estrictamente que marquemos la casilla de exportar en el primer fotograma. Si quito esa selección la imagen no aparece en la película. Me gustaría entender un poco porque, y ¿como hago para que la funcion puzzle utilice la imagen en el segundo fotograma?.

Para que entiendan un poco mas, mi objetivo es simplemente un botón de "Empezar" en el fotograma 1, y que el puzzle comience en el 2. Gracias, les dejo el código.

Código ActionScript :

import flash.display.*;
import flash.geom.*;
import flash.filters.*;
cimg=0; c = 4 ; f = 4; tipo = false; imagen = "imagen";
puzzle("imagen", 4, 4, false);

function puzzle(imagen, f, c, lin) {
   for (hg=0; hg<4*tpz; hg++){pz[hg].removeMovieClip();}
   a=new Array(1,12,0,.35,2,12,1,.15,3,2,4,.2,5,4,6,.5,7,6,8,.5,10,12,2,.15,9,8,10,.4,11,12,10,.15);
   tpz = f*c;
   c>f ? j=20/c : j=20/f;
   bF = new BevelFilter(1,45,0xffffff,.5,0,.5,j,j,4,3,"inner",false);
   img = BitmapData.loadBitmap(imagen);
   w = img.width; h = img.height; m1 = w/(3*c); m2 = h/(3*f);
   if(!cimg){b = []}//solo en demo.
   texto="completo"; // solo en demo.
   // creando matriz delados congruentes entre piezas contiguas
   p = []; d = 0; 
   for (m=0; m<4*tpz; m+=4) {
      p[m+7] = p[m+1] = d++;
      if((d-1)%(2*c) == 2*(c-1)) {p[m+1]=p[(m+4)%(4*tpz) +3]=2*tpz-2};
      p[m+4*c] = p[m+2] = d++;
      if(d>2*(tpz-c) && d%2 == 0) {p[m+2]=p[(m+4*c)%(4*tpz)]=2*tpz-1};
   }
   for (g=0; g<2*tpz; g++) {
      if(!cimg){//solo en demo;
      b[g] = [];
      b[g][0] = new Point(m1, m2);
      alea()<0 ? sig=-1 : sig=1;
      if (g%2 == 0) { //puntos para lados horizontales
         b[g][12] = new Point(m1, 4*m2);
         b[g][4] = new Point(m1-m1*sig*.6, m2*(2+alea()));
         b[g][6] = new Point(m1-m1*sig*.9, m2*(2.5+alea()));
         b[g][8] = new Point(m1-m1*sig*.6, m2*(3+alea()));
      } else { //puntos para lados verticales
         b[g][12] = new Point(4*m1, m2);
         b[g][4] = new Point(m1*(2+alea()), m2-m2*sig*.6);
         b[g][6] = new Point(m1*(2.5+alea()), m2-m2*sig*.9);
         b[g][8] = new Point(m1*(3+alea()), m2-m2*sig*.6);
      }
      for (r=0; r<29; r+=4){ //puntos centrales para H y V 
         b[g][a[r]] = Point.interpolate(b[g][a[r+1]],b[g][a[r+2]],a[r+3]+alea());
      }
   }
   }//fin cimg solo en demo;
   pz = [];
   pt=[];
   for (n=0; n<f*c; n++) {
      pz[n] = createEmptyMovieClip("pz"+n, n+1);
      tmp2 = new BitmapData(5*m1, 5*m2, true, 0);
      pt[n] = new Point((n%c)*3*m1-m1, Math.floor(n/c)*3*m2-m2);
      tmp2.copyPixels(img,new Rectangle(pt[n].x,pt[n].y,5*m1,5*m2),null);
      //dibujando los 4 lados de cada pieza
      for (z=0; z<4; z++) {
         z == 2 ? sy=3*m2 : sy=0; z == 1 ? sx=3*m1 : sx=0;
         g = p[4*n+z];
         pz[n].beginBitmapFill(tmp2);
         pz[n].moveTo(5*m1/2, 5*m2/2);
         pz[n].lineTo(b[g][0].x+sx, b[g][0].y+sy);
         if (g>(2*tpz-3) || lin){pz[n].lineTo(b[g][12].x+sx, b[g][12].y+sy);}
         else {
            pz[n].lineTo(b[g][1].x+sx, b[g][1].y+sy);
            for (j=2; j<12; j+=2){
               pz[n].curveTo(b[g][j].x+sx, b[g][j].y+sy,b[g][j+1].x+sx,b[g][j+1].y+sy);
            }
            pz[n].lineTo(b[g][12].x+sx, b[g][12].y+sy);
         }
         pz[n].lineTo(5*m1/2, 5*m2/2);
         pz[n].endFill();
      }
      //doblando la asignacion para evitar fallos por decimales.
      pz[n]._x = pt[n].x; pt[n].x = pz[n]._x;
      pz[n]._y = pt[n].y; pt[n].y = pz[n]._y;
      pz[n].filters = [bF];
      pz[n].v = n;
   }
   for (h=0; h<tpz; h++) {
      pz[h].onPress = function() {
         this.startDrag();
         this.swapDepths(tpz+1);
      }
      pz[h].onRelease =  pz[h].onReleaseOutside = pz[h].onRollOut = function() {
         this.stopDrag();
         // iman de colocación si está cerca la pieza.
         cerca = new Point(this._x,this._y)
         if (Point.distance(pt[this.v],cerca)< 4+(m1+m2)/15){
            this._x = pt[this.v].x; this._y = pt[this.v].y;
         }
         //comprobador de puzzle completo:
         cnt=0;
         for (tt=0; tt<tpz; tt++){
           if((pz[tt]._y == pt[tt].y) && (pz[tt]._x == pt[tt].x)) {++cnt;}
           cnt==tpz ? texto="completo" : texto="faltan: "+(tpz-cnt);
        }
      }
   }
   cimg=0;//solo en demo
}//fin puzzle

function alea() {return (.1-Math.random()/5);}

mezclar.onPress = function(){ mix(0,0,320,320,0)};

filamas.onPress = function(){
   f++;
   puzzle(imagen, f, c, tipo);
}
filamenos.onPress = function(){
   f>1  ? f-- : f=1;
   puzzle(imagen, f, c, tipo);
}
columas.onPress = function(){
   c++
   puzzle(imagen, f, c, tipo);
}
columenos.onPress = function(){
   c>1 ? c-- : c=1;
   puzzle(imagen, f, c, tipo);
}

mtipo.onPress = function(){
   tipo=!tipo;
   tipo==false ? txtipo = "puzzle" : txtipo = "cuadros";
   cimg=1;
   puzzle(imagen, f, c, tipo);
}

cambio.onPress = function(){
   puzzle(imagen, f, c, tipo);
}
nimagen.onPress = function(){
   imagen == "imagen" ? imagen = "imagen1" :imagen = "imagen";
   cimg=1;
   puzzle(imagen, f, c, tipo);
}
function mix(a,b,c,d,e){ 
   len=pz.length;
   for(var j=0;j<len;j++){
      pz[j]._x=a+(c-a)*Math.random();
      pz[j]._y=b+(d-b)*Math.random();
       if(e){
         as=Math.floor(4*Math.random());
         for(var k=0;k<as;k++){
            rotar90(pz[j]);
         }
      }
   }
}

Por Traffic

1 de clabLevel



 

chrome
Citar            
MensajeEscrito el 15 Ene 2010 05:43 pm
Hay una opcion en File ->Publish Settings ->Pestaña Flash ->en el boton de Settings donde puedes cambiar el numero de frame donde quieres ejecutar desde la biblioteca, espero que te funcione, saludos

Por joshuavw

Claber

306 de clabLevel



Genero:Masculino  

Juego, aprendo y programo

firefox

 

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