Comunidad de diseño web y desarrollo en internet online

Problemas con acciones de un boton

Citar            
MensajeEscrito el 18 Sep 2008 05:51 pm
Hola buenas tardes:
antes que nada quiero que sepais que soy bastante novato en el tema de actionscript por no decir que no sé nada, pero es que me he bajado de internet unos botones con animacion, y no se como ponerles la funcion basica del boton, que es justamnete que me lleve a otro punto de mi pagina, a continuacion trascribo los codigos que tienen, por si alguien pudiera echarme una mano.... muchisimas gracias.


#initclip 0
is_con=function(){}
var a=is_con.prototype=new MovieClip();
// Attaching a number of buttons equal to the amount of items in the array
a.startClip=function(inf){
var i=inf.length;
this.num=i;
while(i--){
var a=this.attachMovie("btn","btn"+i,i);
a._x=i*25;
a.startClip(inf[i],i);
}
}
// Setting the right buttons to active or deactive
a.overFunc=function(id,w){
clearInterval(this.mD);
var i=this.num;
while(i--){
var a=this["btn"+i];
if(i<id){a.setLeft();}
if(i==id){a.setActive();}
if(i>id){a.setRight(w);}
}
}
// When rolled out of a button all buttons will be set to deactive
a.outFunc=function(){
this.mD=setInterval(this,"outActive",200);
}
a.outActive=function(){
clearInterval(this.mD);
var i=this.num;
while(i--){
this["btn"+i].setLeft();
}
}
Object.registerClass("con",is_con);
#endinitclip 0

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 18 Sep 2008 06:33 pm
No es legible el código si no le pones formato.

Código :

[as]
//Pon el código entre tags de Action script
[/as]

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 19 Sep 2008 05:59 pm
gracias, pero es que como te contaba antes no se casi nada de actionscript, en que parte del codigo tengo que ponerlo???

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Sep 2008 07:22 pm
No tiene nada que ver con action script lo que te estoy diciendo, lo que te estaba diciendo es que le des formato al código para leerlo y poder ayudarte, arriba está la explicación de como debes pegar un código de action script aquí en el foro.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 19 Sep 2008 08:11 pm
:? a ver si es asi????

[ #initclip 0
is_btn=function(){}
var a=is_btn.prototype=new MovieClip();
// Setting the right button properties
a.startClip=function(inf,id){
this.id=id;
this.active=false;
this.des.des.text=inf;
this.des.des.autoSize=true;
this.desx=30;
this.des._x=this.desx;
this.sx=this._x;
this.bw=Math.ceil(this.des.des._width)+15;
this.hitArea=this.hit;
this.setMask(this.msk);
}
// Roll over event of the button
a.onRollOver=function(){
this._parent.overFunc(this.id,this.bw);
}
// Roll out event of the button
a.onRollOut=function(){
this._parent.outFunc();
}
// Goto the left position of the button
a.setLeft=function(){
this.active=false;
this.tx=this.sx;
this.tw=22;
this.desx=30;
this.onEnterFrame=this.deActive;
}
// Goto the active position of the button
a.setActive=function(){
this.active=true;
this.tx=this.sx;
this.tw=Math.ceil(this.des.des._width)+15;
this.desx=8;
this.onEnterFrame=this.goActive;
}
// Go to the right position of the button
a.setRight=function(w){
this.active=false;
this.tx=this.sx+(w-22);
this.tw=22;
this.desx=30;
this.onEnterFrame=this.deActive;
}
// Show active version of the button
a.goActive=function(){
this.movePos();
this.msk._width+=(this.tw-this.msk._width)/3;
this.hit._width+=(this.tw-this.hit._width)/3;
this.des._x+=(this.desx-this.des._x)/3;
}
// Show deactive version of the button
a.deActive=function(){
this.movePos();
this.msk._width+=(22-this.msk._width)/3;
this.hit._width+=(22-this.hit._width)/3;
this.des._x+=(this.desx-this.des._x)/3;
}
// Moving the x position of the button
a.movePos=function(){
this._x+=(this.tx-this._x)/3;
this.traceDone();
}
// Check when onEnterFrame event can be deleted
a.traceDone=function(){
var dx=this._x-this.tx;
dx=Math.sqrt(dx*dx);
var dw=this.hit._width-this.tw;
dw=Math.sqrt(dw*dw);
if(dx<.5&&dw<.5){
this._x=this.tx;
this.hit._width=this.tw;
this.msk._width=this.tw;
this.des._x=this.desx;
this.onEnterFrame=null;
}
}
// Release event of the button
a.onRelease=function(){
trace("Clicked button "+this.id);
}
Object.registerClass("btn",is_btn);
#endinitclip 0
]

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Sep 2008 11:04 pm
Como puedes ver no es así, primero mira bien bien la explicación que te dí, no es muy larga que digamos y después ve al foro de pruebas y empieza a probar pegar el código en un post hasta que veas que sale con formato en colores, como este:

Código ActionScript :

function ejecuta(numero:Number):Void{

    trace("una prueba");

}

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 20 Sep 2008 01:16 pm
:) ok, ya lo probé y si funciona, este es el codigo:
Por otro lado disculpa mi ignorancia...


Código ActionScript :

#initclip 0
is_btn=function(){}
var a=is_btn.prototype=new MovieClip();
// Setting the right button properties
a.startClip=function(inf,id){
this.id=id;
this.active=false;
this.des.des.text=inf;
this.des.des.autoSize=true;
this.desx=30;
this.des._x=this.desx;
this.sx=this._x;
this.bw=Math.ceil(this.des.des._width)+15;
this.hitArea=this.hit;
this.setMask(this.msk);
}
// Roll over event of the button
a.onRollOver=function(){
this._parent.overFunc(this.id,this.bw);
}
// Roll out event of the button
a.onRollOut=function(){
this._parent.outFunc();
}
// Goto the left position of the button
a.setLeft=function(){
this.active=false;
this.tx=this.sx;
this.tw=22;
this.desx=30;
this.onEnterFrame=this.deActive;
}
// Goto the active position of the button
a.setActive=function(){
this.active=true;
this.tx=this.sx;
this.tw=Math.ceil(this.des.des._width)+15;
this.desx=8;
this.onEnterFrame=this.goActive;
}
// Go to the right position of the button
a.setRight=function(w){
this.active=false;
this.tx=this.sx+(w-22);
this.tw=22;
this.desx=30;
this.onEnterFrame=this.deActive;
}
// Show active version of the button
a.goActive=function(){
this.movePos();
this.msk._width+=(this.tw-this.msk._width)/3;
this.hit._width+=(this.tw-this.hit._width)/3;
this.des._x+=(this.desx-this.des._x)/3;
}
// Show deactive version of the button
a.deActive=function(){
this.movePos();
this.msk._width+=(22-this.msk._width)/3;
this.hit._width+=(22-this.hit._width)/3;
this.des._x+=(this.desx-this.des._x)/3;
}
// Moving the x position of the button
a.movePos=function(){
this._x+=(this.tx-this._x)/3;
this.traceDone();
}
// Check when onEnterFrame event can be deleted
a.traceDone=function(){
var dx=this._x-this.tx;
dx=Math.sqrt(dx*dx);
var dw=this.hit._width-this.tw;
dw=Math.sqrt(dw*dw);
if(dx<.5&&dw<.5){
this._x=this.tx;
this.hit._width=this.tw;
this.msk._width=this.tw;
this.des._x=this.desx;
this.onEnterFrame=null;
}
}
// Release event of the button
a.onRelease=function(){
trace("Clicked button "+this.id);
}
Object.registerClass("btn",is_btn);
#endinitclip 0

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 20 Sep 2008 06:34 pm
Tu código tiene ya una acción:

Código ActionScript :

// Release event of the button 
a.onRelease = function() {
   trace("Clicked button " + this.id);
};


Cuando los presionas debe lanzarte un mensaje diciéndote "Clicked button X" donde "X" debe ser un número, solo cambia estre trace por la instrucción que deseas, ir a un frame o reproducir a partir del frame que deseas.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 28 Sep 2008 12:10 pm
:( Hola mira la verdad es que me estoy volviendo loco con estos botones, el tema es que son 6 botones que estan cubiertos, cuando tu pasas por encima se desplegan, entonces no entiendo primero, como identificar cada uno de los botones, y segundo lo que quiero es que cada uno de llos vaya a una escena en particular, por lo cual donde tengo que poner el tipico "on release" gotoandplay y la escena????
Perdona que sea tan ignorante, pero ya os habia avisado.

Saludos y muchas gracias.

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Sep 2008 12:43 pm
Lo que te he dicho es que no lo tienes que poner, ya lo tienes puesto, busca en tu código donde está el onRelease no está tan dificil de encontrar, después sustituye el trace que tiene puesto por un gotoAndPlay(frame). Cuando lo tengas hecho entonces se resuelve que todos vayan a un frame diferente.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 29 Sep 2008 04:28 pm
Hola bueno ya tengo un avance, logré que vayan a otra escena, pero el tema es que todos los botones me van a la misma y si le doy dos veces al boton va adelante y atras...
no se hay alguna forma de poder pasarte los botones y que lo puedas mirar???

Desde ya muchas gracias por la ayuda ofrecida.

Saludos.

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 29 Sep 2008 09:02 pm
No, es preferible que postees y se te aclara la duda, así se nutren todos los usuarios de la consulta.

Postea que te devuelve si en el código pones lo siguiente:

Código ActionScript :

a.onRelease = function() { 
   trace(this.id);
}; 

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 30 Sep 2008 04:37 pm
OK, poniendo este codigo lo que hace es lo que me comentabas tu antes, si presiono el primer boton, me sale 0, si presiono el segundo 1 y asi sucesivamente...

Por lgiboudot

4 de clabLevel



 

firefox
Citar            
MensajeEscrito el 30 Sep 2008 10:22 pm
Bueno imagina entonces que tengas un arreglo declarado en el primer frame de tu película (no en el código del clip), que a los frames donde quieras dirigirte con los botones les pongas labels como por ejemplo los siguientes:

Código ActionScript :

var labels:Array = new Array("primerLabel", "segundoLabel", "tercerLabel");


Entonces en tu botón el código debería ser algo como:

Código ActionScript :

a.onRelease = function() {  
   _root.gotoAndPlay(_root.labels[Number(this.id)]); 
};  

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox

 

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