I have a custom class that is extended from MovieClip. The class is basically creating a button that uses frame labels in the MovieClip to move between button states as mouse events are dispatched. Each state (each approx 20 frames long) is terminated with a timeline stop()
.
This class has been used in numerous other projects, but after a certain point in my current application any buttons created as an extension of my button class stop executing the code on the timeline, and just play on a loop. This includes any traces put into the timeline, but all code in the class still executes correctly, even the gotoAndPlay calls when the button state changes.
The strangest part is that no error is thrown by any of the misbehaving button instances on the stage.
What I need are suggestions of what could prevent any o开发者_如何转开发bject that extends a certain class from executing timeline code without throwing an error.
Thanks!
UPDATE: This still has me stumped. Our projects usually come in three parts: a lightweight preloader, a language and age gate, then the main application. Each is loaded into the previous, each time using the current application domain. After the main application has been loaded, any custom display object that extends MovieClip (directly or indirectly) will ignore any actionscript directly on its timeline. The playhead can still be controlled though the class however.
UPDATE 2: This is the code in the test button class that I have made. Notice how there is nothing in it.
package com.test
{
import flash.display.MovieClip;
public class TestLabelButton extends MovieClip
{
public function TestLabelButton():void
{
}
}
}
Update 3: So I've narrowed it down, but it's strange. It seems that I can load my language gate into the preloader just fine, with the language gate being an swf with a custom document class that extends MovieClip. After that though, if I load any more SWFs that contain a custom doc class extending MovieClip it's like all subsequently instantiated MovieClips of extentions thereof loose all the code on their timelines.
From what you describe it sounds like when you run a SWF in the FlashIDE with compile errors.
It will just loop though all the frames.
I am sure you have seen it before normal flash buttons just flicker.
Have you tried to take the offending MovieClip and put it in a new project alone and see what happens?
I'm not sure I fully understand your issue, but this sounds incredibly familiar to a problem I had in the past. I do the same thing. I never use Button symbols and always opt to use a MovieClip instead, since they're more flexible and having all your button state animations immediately exposed I find a much more intuitive way of working.
Any way, make sure that whatever frame you're calling via a frame label / name doesn't have a stop()
on that frame. I've made that mistake a couple of times, where I have a fRollOver frame label at the start of a rollOver animation, and when you gotoAndPlay("fRollOver")
, it just does nothing.
Another thing I've found is, and I've experienced this numerous times, that if you have a stop()
immediately on the first frame, sometimes things brake. Flash just doesn't like it sometimes, and I can't explain this. It certainly works on almost all my projects. It might be a Flash version issue.
My recommendation is to design your movieclip button thing in such a way that any animations needed for the states are happening in their own clips, with their own looping timelines. In other words, each "state" of your button has one frame on the timeline of your button clip thing--no ordinary playing or looping on your main timeline. All playback head control is in your external class, and consists only of *gotoAndStop*s to control the main timeline, and possibly stop() and play() commands to start and stop timelines of the animation clips on each button state frame.
Bottom line, don't attempt to control the playback head of any clip from more than one place, because to do so is to invite weird, often hard-to-reproduce control conflict bugs.
Also, an error in your frame script will stop the Flash Player from executing frame scripts on that clip. Are you getting compile-time errors or warnings?
I believe The_asMan is on the right track. I believe you're either getting a runtime error that's causing this or you've managed to build your object inheritance using the flash IDE in such a way that you've essentially "prototyped" over the MovieClip class. If you were ever an AS2 or AS1 person you'll get what I mean by that. Since your class is essentially empty I'm leaning toward option 2. I believe you've somehow overridden the MovieClip class or prototyped over it using the Flash UI.
OR
You've built out your object wrong and placed multiple instances on the stage at design time. Like this:
The problem of course would be that instead of making this library object a CLASS OF TYPE your custom class, with a unique identifier, you've simply linked the contents of this movie clip to a single class. In this case, creating multiple instances on the stage using the design UI would technically produce errors, so at runtime flash is probably compensating automatically for this mistake by declaring these objects into their own dynamically generated classes, which would blow away all of your functionality in an anomalous way. The proper way to do this would be to either leave your export for actionscript configuration as is and create instances of this class in code, or set the base class of the object to your custom class and give it a unique identifier (if you want to layout in design view, example below).
So now flash knows ahead of time that you've created objects in the design view with a specific base class and knows that you want to inherit from it. In the above condition, the bytecode hits the virtual machine and it goes "WOA, you need 10 copies of the exact same class on the stage? Well that won't work so here let me create some generic objects here for you with those visual contents in them." Anyway I think I'm repeating myself so hopefully this is helpful. Just a theory. :)
精彩评论