开发者

Overriding in Flash IDE

开发者 https://www.devze.com 2023-04-01 03:32 出处:网络
I\'m trying to override dispatchEvent(), with no success in the Flash IDE.Reviewing Adobe docs on the method, it should simply be:

I'm trying to override dispatchEvent(), with no success in the Flash IDE. Reviewing Adobe docs on the method, it should simply be:

override function name()

As demonstrated by Grant Skinner, this is commonly and easily performed:

override public function dispatchEvent(evt:Event):Boolean {
    // code here
}

And while a thorough google search will repeat this syntax successfully used in Class files, doing so inside timeline code, natively in the Flash IDE is proving impossible. The first issue being that the use of public throws the error 1114: The public attribute can only be used inside a package.

That was 开发者_Go百科obvious, however upon removing that, running the following (on the first frame of a new .fla file):

override function dispatchEvent(evt:Event):Boolean {
    trace(evt.type);
    return super.dispatchEvent(evt);
}

results in this error: 1024: Overriding a function that is not marked for override.

Documentation on this error implies that I failed to prefix the identically named function with the override statement, but obviously that's a fallacy, and I'm left flabbergasted as to what the solution may be.

To be clear, we know a class file will work, but that's an irrelavant issue. How do we get override function dispatchEvent() working in timeline code?


You can only override class methods of the class you extend(the base class).
This follows the rules on inheritance.
When you extend a class you inherit all of its methods. Overriding a method allows you to restructure that method. Accessing a method and overriding it are 2 different things.

public class SomethingSomething extends Event{
  public function SomethingSomething ( ):void{
  }
  override public function dispatchEvent(evt:Event):Boolean {
    trace(evt.type);
    return super.dispatchEvent(evt);
  }

}


dispatchEvent() is public, and your code is defualting to the default namespace. You neeed to do override function dispatchEvent(evt:Event):Boolean


1.the following is a class

    package{
        import flash.display.MovieClip
        public class myClass{
            public function myClass(){
                // constructor code
                trace("this is constructor")
                waitToOverride()//trace this is overrided code of waitToOverride
            }
            static function waitToOverride(){
                //wait to override
                trace("this is original code of waitToOverride")
            }
        }
    }

2.the following use in flash IDE.Some object in library link ActionScript class(C):myClass.Then type the following code in object's MainTimeLine

    function waitToOverride(){
        // this will override myClass's waitToOverride method.
        trace("this is overrided code of waitToOverride");
    }
    waitToOverride()//this is overrided code of waitToOverride

ps. juse do it,you will understand what I mean. Edit by Niauwu http://blog.yam.com/celearning/article/28409939

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号