Avatar of nooch44
nooch44
 asked on

How can I make a function call from inside an eventListener

good day,

i am having an issue launching a public function from inside an eventListener function defined to listen for cuePoints. Inside the listener function is also a trace statement, but the trace statement fires every time and the function is ignored. I have attempted debugging the movie but that even ignores the function, its like its not even there. I have also tried renaming the function and even reordering the functions but nothing works. any ideas or help would be appreciated.

thanks

ps - ive attached some of the class as and commented out the function in the constructor that i need to launch from the listener

 
import caurina.transitions.*;

class CLASSNAME {
	
	public var questionCuePoint:Object = new Object();
	
	public function CLASSNAME(){

		_root.scrubBar.questionBubble._alpha = 0;
		_root.scrubBar.questionBubble._xscale = 0;
		_root.scrubBar.questionBubble._yscale = 0;		
		_root.scrubBar.questionsTab.questionTabSheen._alpha = 0;
		_root.scrubBar.questionBubble.questionBubbleSheen._alpha = 0;
		_root.scrubBar.questionBubble.questionBubble_mark._alpha = 0;		
		_root.scrubBar.questionsTab.questionTab_question._alpha = 0;		
		
		_root.FLVPlayer.setSize(720, 406);
		_root.FLVPlayer.skin = null;		
		_root.FLVPlayer.contentPath = "testFLV_cuePoint.flv";
		
		questionCuePoint.time = 5;
		questionCuePoint.name = "questionCue";
//		questionCuePoint.type = "event";
		_root.FLVPlayer.addASCuePoint(questionCuePoint)

//LAUNCHING THIS WAY WORKS FINE
//		questionBubble(); 

		questionTabMouse();
		_root.FLVPlayer.addEventListener("cuePoint", cuePointListener);
	}
	
	private function questionBubble(){		
		Tweener.addTween(_root.scrubBar.questionBubble, {_alpha:100, _xscale:100, _yscale:100, time:.32, transition:"easeOutBack", onComplete:questionTabSheen});
	}

	public function cuePointListener(eventObject:Object){

		
		trace(eventObject.info.name);

		switch(eventObject.info.name){
			case "questionCue":

//LAUNCHING THIS WAY DOES NOT WORK
			questionBubble();
			trace("questionBubble();");
			break;
		}
		
	}	
	
	public function questionTabSheen(){		
		
		Tweener.addTween(_root.scrubBar.questionsTab.questionTab_question, {_alpha:100, time:.5, transition:"easeInExpo", onComplete:function(){Tweener.addTween(_root.scrubBar.questionsTab.questionTab_question, {_alpha:0, time:.5, transition:"easeOutExpo"});}});
		Tweener.addTween(_root.scrubBar.questionsTab.questionTabSheen, {_alpha:48, _x:381, time:1, transition:"easeOutExpo"});

		Tweener.addTween(_root.scrubBar.questionBubble.questionBubbleSheen, {_alpha:48, _x:102, delay:.5, time:1, transition:"easeOutExpo"});
		Tweener.addTween(_root.scrubBar.questionBubble.questionBubble_mark, {_alpha:100, delay:.5, time:.5, transition:"easeInExpo", onComplete:function(){Tweener.addTween(_root.scrubBar.questionBubble.questionBubble_mark, {_alpha:0, time:.5, transition:"easeOutExpo"});}});

	}	

	public function questionTabMouse(){
		
		_root.scrubBar.questionsTab.onRelease = function(){
			Tweener.addTween(_root.scrubBar.questionBubble, {_alpha:100, _xscale:0, _yscale:0, time:.32, transition:"easeInBack", onComplete:function(){Tweener.addTween(_root.scrubBar.questionsTab, {_y:50, delay:.5, time:.64, transition:"easeOutExpo"});}});
		}
		
		_root.scrubBar.questionsTab.onRollOver = function(){
			_root.scrubBar.questionsTab.questionTabSheen._alpha = 0;
			_root.scrubBar.questionsTab.questionTabSheen._x = 0;					
			Tweener.addTween(_root.scrubBar.questionsTab.questionTab_question, {_alpha:100, time:.5, transition:"easeInExpo", onComplete:function(){Tweener.addTween(_root.scrubBar.questionsTab.questionTab_question, {_alpha:0, time:.5, transition:"easeOutExpo"});}});
			Tweener.addTween(_root.scrubBar.questionsTab.questionTabSheen, {_alpha:48, _x:381, time:1, transition:"easeOutExpo"});
		}
		
	}
	
}

Open in new window

Adobe Flash

Avatar of undefined
Last Comment
moagrius

8/22/2022 - Mon
moagrius

so you're getting the trace("questionBubble()") to fire?

try sticking a trace in the questionBubble function itself, to see if the problem is locating the reference, or if it's really not firing at all, and post back
nooch44

ASKER
thanks for the response moaqruis...i have tried that already, i placed a trace statement above the Tween in the questionBubble function and one below it to see if it fires at all and i get nothing. and when i debug and place a break point on the function call or even inside the function itself it simply jumps over it as if it werent there
moagrius

AS2 classes are weird...

try changing this:

 trace("questionBubble();");

to this:

 trace("questionBubble is a:" + questionBubble);

to see if it's recognized as a function

you can also try:

this.questionBubble();

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
nooch44

ASKER
this.questionBubble(); does nothing...but the new trace statement comes back with " questionBubble is a:undefined"
moagrius

just guessing at this point...  but now we know that the function isn't even defined...  try tracing out that same thing:

 trace("questionBubble is a:" + questionBubble);

elsewhere, like in the constructor, just to see if it's defined at any point...

also might try making it (the questionBubble function) public instead of private...
nooch44

ASKER
in the constructor this is traced "questionBubble is a:[type Function]"...so its definitely defined...and ive tried all combo's of publc/private to no avail...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
moagrius

sorry to keep throwing all these traces at you, but this is the only way i can think to debug this...

try tracing trace("questionBubble is a:" + questionBubble); in the function but outside the switch...

if that works, and it's not undefined, we can stuff it in a local variable in the switch and call that...
nooch44

ASKER
inside that function but outside the switch it is still giving me 'undefined'...
moagrius

maybe scope is getting lost...  inside the function:

trace(this);
trace(this.constructor);

if it's coming back CLASSNAME (as it should), i'm stumped...  if it comes back something else (like the FLV component or the event itself), then we can try to set up a ref to the class elsewhere and pass that in, and call the method from that
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
nooch44

ASKER
those traces return...

_level0.FLVPlayer
[type Function]
moagrius

aha!

we lost scope with the listener

try this

set up a private variable:

private var ref;

then in the constructor, define it:

ref = this;

then in the listener, try:

ref.questionBubble();
nooch44

ASKER
same result...i tried it in the switch and out of the switch and also traced 'ref.questionBubble'  in both places...both returned undefined still
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
moagrius

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
nooch44

ASKER
got the error 'Instance variables cannot be accessed in static functions.' so i tried defining a public/private var to hold the instance name and got the same error
moagrius

that's probably the onComplete property "questionTabSheen" - try making that a public static member as well

nooch44

ASKER
haHA!...perfect...works perfectly...can you explain why it needed to be static?...and thanks for the help...i was going nuts all day tryiung to figure it out
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
moagrius

cos AS2 is retarded : )

the problem was scope - when nothing is specified, the VM looks for the variable inside "this"...  the event listener was being called from the FLV component, which obviously doesn't have a method called "questionBubble" - so once we figured that out, we had to see how we could access the method from the FLV component - the easiest way was just to assign it to the class itself, not any particular instance...

terrible explanation but i gotta run - we got this figured out just in time - glad it's working for ya