Comunidad de diseño web y desarrollo en internet online

Problema con tween

Citar            
MensajeEscrito el 24 Feb 2010 10:07 pm
Hola amigos a pesar que he consultado mucha veces a este sitio nunca hice una pregunta. Seré breve estoy comenzando a utilizar as3 mi problema es este:
Estoy haciendo una botonera y uso un sprite, cuando aprieto en un botón la caja siempre arranca a moverse desde el mismo lugar. Quisiera que lo haga desde la ultima posición que estuvo la caja. Me ayudan? No se me ocurre como hacerlo. Quizás cuando sepa mas algún día pueda ayudar yo pero no se mucho por ahora.
Aqui pongo el swf para que se entienda.
file:///G:/mover_mc.swf
Aqui esta el codigo:

Código ActionScript :

import flash.events.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var caja:Sprite= new Sprite   
caja.graphics.beginFill(0xfff000); 
caja.graphics.drawRect(0,0,20,20); 
caja.graphics.endFill(); 
caja.x=65  
caja.y=30
addChild(caja); 
stage.frameRate=40

a_btn.addEventListener(MouseEvent.CLICK, aMover);
b_btn.addEventListener(MouseEvent.CLICK, bMover);
c_btn.addEventListener(MouseEvent.CLICK, cMover);
d_btn.addEventListener(MouseEvent.CLICK, dMover);

var pos:Number= caja.x ;
 
var a:Number = 15
var b:Number = 65
var c:Number = 115
var d:Number = 165

var efec_c:Tween = new Tween(caja,"x",Regular.easeInOut, pos,c,2, true)
var efec_d:Tween = new Tween(caja,"x",Regular.easeInOut, pos,d,2, true) 
var efec_a:Tween = new Tween(caja,"x",Regular.easeInOut,pos,a,2, true)
var efec_b:Tween = new Tween(caja,"x",Regular.easeInOut, pos,b,2, true)

function aMover(event:MouseEvent):void
       {
      this.efec_a.start();
      }
function bMover(event:MouseEvent):void
       {
      this.efec_b.start();
      }
function cMover(event:MouseEvent):void
       {
      this.efec_c.start();
      }
function dMover(event:MouseEvent):void
       {
      this.efec_d.start();
      }

Por fabioroldan

1 de clabLevel



 

msie8
Citar            
MensajeEscrito el 25 Feb 2010 12:21 am
Hola , una solucion seria colocar la variable pos dentro de la funcion junto con el Tween algo asi.

Código ActionScript :

function aMover(event:MouseEvent):void        {     
var pos:Number= caja.x ; 
var efec_a:Tween = new Tween(caja,"x",Regular.easeInOut,pos,a,2, true) ;
  efec_a.start();      
 } 

asi asignaria la ultima posicion de x a caja.

estoy usando una libreria que es mucho mas sencilla y confiable se llama TweenMax te la recomiendo es muy poderosa .
espero que te sirva. saludos

Por maximil13

70 de clabLevel



Genero:Masculino  

Programador, estudiante de sistemas.

msie7
Citar            
MensajeEscrito el 26 Feb 2010 02:36 am
Hola lo probé y no pude hacerlo andar, de hecho no me aparece el sprite. Pero me baje la clase esta tweenmax voy a probar. Alguien sabe como se sube un swf al foro? Igual muchas gracias por la intención. Voy a seguir probando...

Por fabioroldan

1 de clabLevel



 

chrome
Citar            
MensajeEscrito el 26 Feb 2010 07:48 am

Código ActionScript :

import flash.events.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var cajaTween:Tween;

var caja:Sprite = new Sprite  ;
caja.graphics.beginFill(0xfff000);
caja.graphics.drawRect(0,0,20,20);
caja.graphics.endFill();
caja.x = 65;
caja.y = 30;
addChild(caja);
stage.frameRate = 40;

a_btn.addEventListener(MouseEvent.CLICK, aMover);
b_btn.addEventListener(MouseEvent.CLICK, bMover);
c_btn.addEventListener(MouseEvent.CLICK, cMover);
d_btn.addEventListener(MouseEvent.CLICK, dMover);

var pos:Number = caja.x;

var a:Number = 15;
var b:Number = 65;
var c:Number = 115;
var d:Number = 165;

function aMover(event:MouseEvent):void
{
   cajaTween = new Tween(caja, "x", Regular.easeInOut, caja.x, a, 2, true);
}
function bMover(event:MouseEvent):void
{
   cajaTween = new Tween(caja, "x", Regular.easeInOut, caja.x, b, 2, true);
}
function cMover(event:MouseEvent):void
{
   cajaTween = new Tween(caja, "x", Regular.easeInOut, caja.x, c, 2, true);
}
function dMover(event:MouseEvent):void
{
   cajaTween = new Tween(caja, "x", Regular.easeInOut, caja.x, d, 2, true);
}

PD: Haz caso a maximil13, hay otras librerías de Tween que son mejores que la de Flash

Por isidoro

Claber

498 de clabLevel

2 tutoriales

Genero:Masculino  

firefox

 

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