Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-11-2006, 07:31 PM   #1
cnatale
Registered User
 
Join Date: Apr 2006
Posts: 22
Default custom transitionmanager class problem/class scope?

I'm writing a class that fades from one scene to another in a video game. A custom transitionManager object is created, and a listener is attached. Once the fade out from one scene is complete, the listener is triggered, the scene switches, and the new scene fades in.

This is the error I'm getting: "There is no method with the name 'myTransitionManager'.
myTransitionManager.addEventListener("allTransitio nsOutDone", fadeListener);"
. It is given everytime myTransitionManager is accessed by any of the class functions.

I assume this is a class scope issue. How can I create a custom transitionManager object accessable to the entire class? I need it to be accessed by at least three separate class functions.

Here's the source, starting with the constructor for the GameSection class:

Code:
	public function GameSection(clip_to_fade:MovieClip){
			var myTransitionManager:TransitionManager = new TransitionManager();
	}
	
	//class methods
	
	function switch_section(clip_to_fade:MovieClip, fade_in_scene:String) {
		// Define a listener object to use with the Tween objects.
		var fadeListener:Object = new Object();
		//create event listener for transitions being complete
		fadeListener.allTransitionsOutDone = function(eventObj:Object) {
    		trace("allTransitionsOutDone event occurred.");
			gotoAndPlay(fade_in_scene);
			fadeIn(clip_to_fade);
		};
		myTransitionManager.addEventListener("allTransitionsOutDone", fadeListener);
		
		
		fadeOut(clip_to_fade);
	}
	
	function fadeIn(in_mc:MovieClip) {
		myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone});
	}
	
	function fadeOut(out_mc:MovieClip) {
		myTransitionManager.start(out_mc, {type:Fade, direction:Transition.OUT, duration:1, easing:None.easeNone});		
	}


Thanks!
cnatale is offline   Reply With Quote
Old 08-11-2006, 07:44 PM   #2
deadbeat
Registered User
 
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
Default

Don't define it as a var in the constructor, make it a property of the class...ie:
ActionScript Code:
class GameSection{ var myTransitionManager:TransitionManager public function GameSection(clip_to_fade:MovieClip){     myTransitionManager = new TransitionManager(); } //...etc...
K.
deadbeat is offline   Reply With Quote
Old 08-11-2006, 08:06 PM   #3
cnatale
Registered User
 
Join Date: Apr 2006
Posts: 22
Default

When I try this, I get a different error on every occasion myTransitionManager is called, Static members can only be accessed directly through classes. For example, myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone}); throws this error.


I'm still pretty new to OOP. Could someone explain what this means?
cnatale is offline   Reply With Quote
Old 08-11-2006, 08:12 PM   #4
deadbeat
Registered User
 
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
Default

It looks like your TransitionManager has a static function called start...?

K.
deadbeat is offline   Reply With Quote
Old 08-11-2006, 08:17 PM   #5
jharmon
Registered User
 
Join Date: Nov 2005
Posts: 56
Default

I'm not really familiar with the TransitionManager class, but after looking at the documentation, it seems that you are supposed to pass a movieClip parameter to the constructor.

From the Flash documentation:

When you create a new instance of a TransitionManager class by using the new operator, you must designate a target movie clip in the content parameter for its constructor. The constructor for the mx.transitions.TransitionManager class has the following parameter name and type:
TransitionManager(content:MovieClip)
jharmon is offline   Reply With Quote
Old 08-11-2006, 08:44 PM   #6
cnatale
Registered User
 
Join Date: Apr 2006
Posts: 22
Default

Yeah, you're right, Deadbeat. I opened up the TransitionManager class, and the function start is static. I'll start looking into ways around this, but if anyone has ideas, don't be shy. Thanks!
cnatale is offline   Reply With Quote
Old 08-11-2006, 08:46 PM   #7
deadbeat
Registered User
 
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
Default

Well, a static function just means you call the function directly on the class, instead of creating an instance first...like the Math class - you dont need to do this:
ActionScript Code:
var myMath=new Math(); num=myMath.round(1.5);
You just call the method directly:
ActionScript Code:
num=Math.round(1.5);
K.
deadbeat is offline   Reply With Quote
Old 08-11-2006, 08:47 PM   #8
jharmon
Registered User
 
Join Date: Nov 2005
Posts: 56
Default

well the documentation has it shown almost exactly as yours is done. only difference is that they passed a movieclip parameter into their constructor...
jharmon is offline   Reply With Quote
Old 08-11-2006, 10:09 PM   #9
cnatale
Registered User
 
Join Date: Apr 2006
Posts: 22
Default

Deadbeat, if I try your advice, I get a Static members can only be accessed directly through classes error. This error doesn't make a bit of sense to me, because as jharmon points out, the actionscript manual tells you to create a new object when attaching listeners to TransitionManager.

The reason I can't do it exactly as the flash manual suggests, jharmon, is that i need to be able to use a movieclip value passed to the class through the GameSection constructor. If I declare the TransitionManager as a class variable, I can't pass the movieclip to be faded onto it. If I declare the TransitionManager in the constructor, it doesn't seem to the the scope to allow other class functions to access it, which is vital. Sort of a catch-22, and extremely frustrating...
cnatale is offline   Reply With Quote
Old 08-11-2006, 10:19 PM   #10
deadbeat
Registered User
 
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
Default

From the docs:

If you create a TransitionManager instance by using the new operator, you must then designate the properties of the transition that you want to apply and follow with a call to start the transition using the TransitionManager.startTransition() method; otherwise, the transition is not applied to a movie clip or started. For details about the TransitionManager.startTransition() method, its use, and parameters, see TransitionManager.startTransition(). A quick alternative to the two-step process of creating a TransitionManager instance is to simply call the TransitionManager.start() method; for more information, see TransitionManager.start(). The TransitionManager.start() method allows you to create a TransitionManager instance, provide the target movie clip, and specify the transition properties in one call.

I think you're trying to mix the two techniques when you need to go with one or the other...

K.
deadbeat is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the mx.util.Delegate class within your classes! madgett ActionScript 2.0 3 09-02-2007 11:11 PM
ColorTransform within custom class wmbenedetto ActionScript 2.0 2 05-12-2006 07:59 AM
Custom Class, Xml, Scope ..... Help!!! crabby80 ActionScript 2.0 8 02-08-2005 11:43 AM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM


All times are GMT. The time now is 11:50 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.