J'ai ce code AS2 qui fait quelques animations simples quand je roule un mc en utilisant TweenLite. Je sens que j'ai beaucoup de code répétitif.Raccourcir le code de fonction et convertir la variable
Y at-il un moyen d'être en mesure de préciser simplement une fonction comme celui-ci
boxLink (a);
et avoir le reste du code, avec le chemin vers le MovieClip cible dans la fonction au lieu de dans la variable de fonction?
Comment puis-je rendre ce code aussi court que possible?
Est-il possible de convertir une variable: String en une variable: MovieClip? Comment ferais-je cela dans cet exemple?
import gs.*;
import gs.easing.*;
function imageAlpha(mc_target:MovieClip) {
mc_target.onRollOver = function() {
TweenLite.to(mc_target,1,{_alpha:100, ease:Back.easeOut});
};
mc_target.onRollOut = function() {
TweenLite.to(mc_target,1,{_alpha:60, ease:Back.easeOut});
};
}
function boxLink(mc_function:MovieClip, mc_target:MovieClip, mc_image:MovieClip, linkURL:String) {
mc_function.onRollOver = function() {
TweenLite.to(mc_target,0.5,{_xscale:150, _yscale:150, ease:Back.easeOut});
TweenLite.to(mc_image,1,{_alpha:100, ease:Back.easeOut});
};
mc_function.onRollOut = function() {
TweenLite.to(mc_target,0.5,{_xscale:100, _yscale:100, ease:Back.easeOut});
TweenLite.to(mc_image,1,{_alpha:60, ease:Back.easeOut});
};
mc_function.onRelease = function() {
if (linkURL) {
getURL(linkURL);
}
};
}
imageAlpha(a_box.image);
imageAlpha(b_box.image);
imageAlpha(c_box.image);
imageAlpha(d_box.image);
boxLink(a_box.link1,a_box.arrow1,a_box.image,'http://www.google.no');
boxLink(a_box.link2,a_box.arrow2,a_box.image,'http://www.google.no');
boxLink(a_box.link3,a_box.arrow3,a_box.image,'http://www.google.no');
boxLink(b_box.link1,b_box.arrow1,b_box.image,'http://www.google.no');
boxLink(b_box.link2,b_box.arrow2,b_box.image,'http://www.google.no');
boxLink(b_box.link3,b_box.arrow3,b_box.image,'http://www.google.no');
boxLink(c_box.link1,c_box.arrow1,c_box.image,'http://www.google.no');
boxLink(c_box.link2,c_box.arrow2,c_box.image,'http://www.google.no');
boxLink(c_box.link3,c_box.arrow3,c_box.image);
boxLink(d_box.link1,d_box.arrow1,d_box.image,'http://www.google.no');
boxLink(d_box.link2,d_box.arrow2,d_box.image,'http://www.google.no');
boxLink(d_box.link3,d_box.arrow3,d_box.image);
En vim juste faire 'ggdGzz' qui va résoudre votre problème – Qix