1

私はAction-script OOPが初めてで、私が持っているこの例のようなメソッドをチェーンする方法を知る必要があります

I.$(button).bind('click',clickButton).bind('rollover',overButton).bind('rollout',outButton)

まず、jQuery のようにドル記号のみを使用するには、を削除する必要がありI.ます:) MovieClip を選択し、それに任意のアクションを適用します。ここでアクションを呼び出した最後の人は、私が何を意味するかを知るためのクラスコードです:

package com.MAIN
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    public class I extends Sprite
    {
        private static var cSelector:Sprite;

        public static function $(selector:Sprite)
        {
            cSelector = selector
            return I;
        }

        public static function alpha(val:Number)
        {
            cSelector.alpha = val;
            return I;
        }

        // bind mouse event to the element
        public static function bind(EventStr,func:Function)
        {
            var func1:Function = function(e:MouseEvent){
                func(cSelector);
            }
            // select the event from the list
            if(typeof(EventStr) == 'string'){
                // map the events in lowercase
                var events:Object = {click:'CLICK',rollover:'ROLL_OVER',rollout:'ROLL_OUT',dblclick:'DOUBLE_CLICK',mousedown:'MOUSE_DOWN',mousemove:'MOUSE_MOVE',mouseout:'MOUSE_OUT',mouseover:'MOUSE_OVER',mouseup:'MOUSE_UP',mousewheel:'MOUSE_WHEEL'};
                // check if the event exists in the list
                if(events[EventStr] && MouseEvent[events[EventStr]]){
                    cSelector.addEventListener(MouseEvent[events[EventStr]],func1);
                }
            }else if(typeof(EventStr) == 'object'){
                // add the event
                cSelector.addEventListener(EventStr,func1);
            }
            return I;
        }

        public static function remove()
        {
            cSelector.parent.removeChild(cSelector);
            return I;
        }

    }
}
4

2 に答える 2

2

さあ、正しい方向へのいくつかのステップです。しかし、これは本当に、本当に、本当にくだらない考えです。

//$.as
package
{
    import flash.display.DisplayObject;

    //NOTE: there's NO class definition

    public function $( selector : DisplayObject ) : IDisplayObject
    {
        //traverse displaylist to find <code>selector</code>
        //and return an instance of IDisplayObject that holds the reference        
    }
}

//IDisplayObject.as
package
{
    public interface IDisplayObject{
        function alpha( value : Number ) : IBinding;
    }
}

//IBinding.as
package jquery
{
    public interface IBinding{
        function bind( eventName : String, callback : Function, ...parameters ):void;
    }
}

これらの具体的な実装を作成したら、次のことができます。

$( someMC ).alpha( .5 ).bind( 'click', function(){ trace( 'what a miraculously crappy idea !!!!' ) } );
于 2013-03-06T15:18:01.450 に答える
1

次のように試すことができます。

interface Test {
  function doBla(): Test
  function moreBla(): Test
}

public class StaticTest {
  private static const instance: Test = new InternalTest()

  public static doBla() : Test {
    return instance.doBla();
  }

  public static moreBla() : Test {
    return instance.moreBla();
  }
}

internal class InternalTest implements Test {
  function doBla(): Test {
    trace("bla");
    return this;
  }

  function moreBla(): Test {
    trace("more bla");
    return this;
  }
}
于 2013-03-05T17:15:30.217 に答える