08-11-2006, 07:31 PM
|
#1
|
|
Registered User
Join Date: Apr 2006
Posts: 22
|
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!
|
|
|
08-11-2006, 07:44 PM
|
#2
|
|
Registered User
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
|
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.
|
|
|
08-11-2006, 08:06 PM
|
#3
|
|
Registered User
Join Date: Apr 2006
Posts: 22
|
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?
|
|
|
08-11-2006, 08:12 PM
|
#4
|
|
Registered User
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
|
It looks like your TransitionManager has a static function called start...?
K.
|
|
|
08-11-2006, 08:17 PM
|
#5
|
|
Registered User
Join Date: Nov 2005
Posts: 56
|
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)
|
|
|
08-11-2006, 08:44 PM
|
#6
|
|
Registered User
Join Date: Apr 2006
Posts: 22
|
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!
|
|
|
08-11-2006, 08:46 PM
|
#7
|
|
Registered User
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
|
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:
K.
|
|
|
08-11-2006, 08:47 PM
|
#8
|
|
Registered User
Join Date: Nov 2005
Posts: 56
|
well the documentation has it shown almost exactly as yours is done. only difference is that they passed a movieclip parameter into their constructor...
|
|
|
08-11-2006, 10:09 PM
|
#9
|
|
Registered User
Join Date: Apr 2006
Posts: 22
|
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...
|
|
|
08-11-2006, 10:19 PM
|
#10
|
|
Registered User
Join Date: Feb 2001
Location: vancouver
Posts: 2,219
|
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:07 AM.
///
|
|