A button array question


i think should here instead of actionscrip area not sure.  using button have small popup (which movieclip) appear when user mouse over.  have lot of these because list of bullet points.  i'm wondering if there way array.  cut way down on code.

 

i've been searching on net , in adobe haven't had luck.

 

thanks.

 

suzette

 

although flash forum instead of actionscript code 1 button is: 

 

box_new90.btn_newusers.addeventlistener(mouseevent.mouse_over, newuserover);
box_new90.btn_newusers.addeventlistener(mouseevent.mouse_out,closepop);

 

function newuserover(e:mouseevent):void{
activepop = pop_newusers;
heightpop = 75;
toppopopen = 190;
toppopclose = 155;
openpop();
}

 

function openpop() {
var tweenshow:tween = new tween(activepop, "alpha", none.easein, 0,1,3,false);
var tweengrow:tween = new tween(activepop,"height",none.easein, 0,heightpop,3,false);
var tweenmovedown:tween = new tween(activepop,"y",none.easenone,toppopclose,toppopopen,3,false);
}


function closepop(e:mouseevent):void{
var tweenhide:tween = new tween(activepop, "alpha", none.easeout, 1,0,3,false);
var tweenshrink:tween = new tween(activepop,"height",none.easeout,heightpop,1,3,false);
var tweenmoveup:tween = new tween(activepop,"y",none.easenone,toppopopen,toppopclose,3,false);
// activepop.y = toppop;
}

i'm not sure thinking of using array accomplish, though helpful in aspects.

as minimum, array come in handy assigning event listeners.  if array held btn objects, loop thru array assign event listeners.

 

you utilize same 3 functions of buttons if modify things slightly.  renaming buttons remove "btn_" portion avoid line of code (the line otherwise needed extract unique part of names).

 

box_new90.newusers.addeventlistener(mouseevent.mouse_over, newuserover);
box_new90.newusers.addeventlistener(mouseevent.mouse_out,closepop);

 

 

 

function newuserover(e:mouseevent):void{
activepop = this["pop_"+e.currenttarget.name];
heightpop = 75;
toppopopen = 190;
toppopclose = 155;

openpop();
}

 

 

 

function openpop() {
var tweenshow:tween = new tween(activepop, "alpha", none.easein, activepop.alpha,1,3,false);
var tweengrow:tween = new tween(activepop,"height",none.easein, activepop.height,heightpop,3,false);
var tweenmovedown:tween = new tween(activepop,"y",none.easenone, activepop.y,toppopopen,3,false);
}


function closepop(e:mouseevent):void{
var tweenhide:tween = new tween(activepop, "alpha", none.easeout,  activepop.alpha,0,3,false);
var tweenshrink:tween = new tween(activepop,"height",none.easeout,activepop.height,1,3,false);
var tweenmoveup:tween = new tween(activepop,"y",none.easenone,activepop.y,toppopclose,3,false);
// activepop.y = toppop;
}

 

 

the reason highlighted things red...

 

 

for newuserover function, if value different each popup, that's 1 place array come in handy... array included objects specify 3 parameters each popup.  make use of array, need have btn provide identifier index of array.  done making btn movieclip carries variable index.

 

 

for 3's in tween code, you'll notice changed beginning value of tweens use current value of popup associated property.  in event of moving mouse over/out of button faster tween speed. tween begin rather jumping full value of property.  in case, 3's established variable amount rather fixed values you're not waiting full 3 seconds part way thru it's tween when reversing tween occurred.  3 replaced like... 3*math.abs(initial-final)/fullinitial...  depend on property/scenario you're dealing with... don't wanna dividing zero.



More discussions in Adobe Animate CC - General


adobe

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???