Hi there, this is a weird problem that I am sure has a really simple
solution.
I have written a custom class that is instantiated by another custom
class. I pass a few variables to the class and I can trace them going
in and check that they are set but when I go to use them again they
are undefined, if I trace them from the class they are undefined.
However, if I trace the variables from the main timeline they appear
fine.
I'm not sure what is going on with this, I think I am declaring my
class or variables incorrectly though i can't see where.
I have been battling with this since yesterday, if anyone could
suggest a possible solution it would be a massive help. The class is
at the bottom of the email.
Thanks,
Ali
//
// AnimLib
//
import gs.TweenFilterLite;
import quest.StepAnimator;
import mx.utils.Delegate;
class Classes.AnimLib{
var anims_ar:Array;
var mainMC:MovieClip;
//animation abjects/times
var genericTime:Number = 0.5;
public var sA:StepAnimator;
var genericIn:Object;
var genericOut:Object;
var mcO:MovieClip;
//individual animation objects
var umbrellaIn:Object = {autoAlpha:50, overwrite:true, time:5};
public function AnimLib(m:MovieClip, s:StepAnimator) {
trace("animLib created");
mainMC = m;
trace("step animator passed:"+s);
sA = s;
trace("step animator set:"+sA);
initObs();
linkAnims();
trace("starting tween");
}
private function initObs() {
genericIn = new Object();
trace("GENERICIN CREATED:"+genericIn);
genericOut = new Object();
genericIn = {autoAlpha:100, overwrite:true, time:1};
genericOut = {autoAlpha:0, overwrite:true, time:0.5};
trace("genericIn properties added:"+genericIn);
trace("init obs triggers test");
}
//only holds references for objects that have a group or a function
assigned to them (more comple)
private function linkAnims() {
//this[0] = {mc:"escapes", group:"generic"};
//this[0] = {mc:"escapes", group:generic};
anims_ar = new Array();
anims_ar[0] = {mc:"intro", fn:"intro"};
}
public function animDone() {
trace("mainMC:"+mainMC);
sA.animDone();
//_root.stepA.animDone();
this.sA.animDone();
}
function testIt() {
trace("testest :):):):):)");
}
//introduction animation
public function introAnim(m:MovieClip, b:Boolean) {
trace("! ! ! ! ! -----introAnim triggered:"+m+b);
genericIn = {autoAlpha:100, overwrite:true, time:1};
genericOut = {autoAlpha:0, overwrite:true, time:0.1};
m = mainMC.intro;
m._alpha = 100;
//create array of mcs then add delay thru loop,
var mc_ar:Array = new Array(m.sitePhoto, m.topTitle, m.title,
m.escapes, m.ans0, m.ans1);
var alph:Number = 100
if (!b) {
alph = 0;
}
trace("intro vis:"+_root.intro._visible+" alpha:"+_root.intro._alpha
+" alph:"+alph);
//TweenFilterLite
for ( var i=0; i<mc_ar.length; i++ ) {
if (i==mc_ar.length-1) {
TweenFilterLite.to(mc_ar[i], 1,{_alpha:alph, overwrite:true,
delay:.5*i, onComplete:animDone});
}else{
TweenFilterLite.to(mc_ar[i], 1,{_alpha:alph, overwrite:true,
delay:.5*i});
}
};
}
//custom test function where more than one animation has to happen
function escapeFun(m:MovieClip, inO:Boolean) {
trace("escapefuncalled:"+m);
//assigns generic obj
var tmpObj:Object = genericIn;
//then modifies it
tmpObj.time = 2;
//m._visible = true;
TweenFilterLite.to(m,1,{autoAlpha:100});
}
//is passed a mc and animates it in or out
public function animate(m:MovieClip, i:Boolean) {
var animObj:Object = returnAnimObj(m, i);
trace("returned object:"+animObj);
//animate
if (animObj.undefined == 1) {
trace("UNDEFINED ANIM OBJECT RETURNED (fn/group?)");
// intro();
} else {
trace("animating...");
TweenFilterLite.to(m,animObj.time,animObj);
}
}
private function returnAnimObj(mc:MovieClip, ins:Boolean):Object {
trace("returnAnimObj:"+mc);
var inStr:String = "In";
if (!ins) {
inStr = "Out";
}
var retObj:Object = new Object();
for (var i = 0; i<anims_ar.length; i++) {
trace("imc:"+anims_ar[i].mc);
//object is in the array and so has a group
if (anims_ar[i].mc == mc._name) {
if (anims_ar[i].group != undefined) {
trace("mc has a group referenced");
retObj =
anims_ar[anims_ar[i].group+inStr];
} else if (anims_ar[i].fn != undefined) {
//mc has a function assigned
trace("a function is assigned!");
retObj.undefined = 1;
if (anims_ar[i].fn=="intro"){
introAnim(mainMC.intro, true);
}else{
this[anims_ar[i].fn].apply(null,[mc, ins]);
}
break;
}
} else {
//object not in array so has individual anim
trace("the object is not in the array :(");
retObj = anims_ar[mc._name+inStr];
if (retObj == undefined) {
trace("| - - - - - |");
trace("THERE IS NO REFERENCE TO THIS MC IN
ANIMLIB");
//retObj = this["generic"+inStr];
retObj.undefined = 1;
}
}
}
return retObj;
}
}
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders