Re: [問題] extends & super in書本上的例題

看板Flash作者 (CJ Cat)時間18年前 (2007/11/19 13:43), 編輯推噓6(601)
留言7則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《icedesign (不可或缺的咖啡因)》之銘言: : function Bouncer(targetMC:MovieClip){ : super(targetMC,xVel,yVel) : } : 然後它又說不用寫也跑的動,但是我的不寫就是不動。 : 為什麼改了之後,ball_mc卻可以動呢? 沒錯,應該是書上寫錯了 因為少給xVel和yVel,super根本就不知道這兩個變數是從哪裡來的啊 或者可以利用 function接收變數數量沒有限制 這個特型 來做到一樣的效果 這樣的話Bouncer的constructor連一個參數都不需要定義 缺點是debug上面比較困難 public function Bouncer() { if(arguments.length == 3) { if((arguments[0] instanceof MovieClip) && (typeof arguments[1] == "number") && (typeof arguments[2] == "number")) { super(arguments[0], arguments[1], arguments[2]); } else { throw Error("Wrong arguments passed"); } } else { throw Error("Wrong arguments passed"); } } -- CJ Cat = Croa'J Cat = Cockroach Cat = 西街凱特 = 蜚蠊貓 = 蟑螂貓 Gallery http://cjcat2266.deviantart.com ptt2 Board CJWorkshop - 阿多比閃光(Adobe Flash)研討區 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.234

11/19 14:40, , 1F
唉唷~限制這招讚喔!又多學到一招,感謝貓大~哈哈
11/19 14:40, 1F
※ 編輯: cjcat2266 來自: 140.112.4.234 (11/19 15:02)

11/19 15:39, , 2F
但是AS3就有限制arguments數量囉
11/19 15:39, 2F

11/19 15:42, , 3F
傳入的arguments數量必須比function definition的還多
11/19 15:42, 3F

11/19 21:02, , 4F
那就來個function overload囉,就沒這個限制了 :)
11/19 21:02, 4F

11/20 00:01, , 5F
我記得...Flash沒有function overloading吧?
11/20 00:01, 5F

11/20 00:02, , 6F
就只能靠arguments來決定
11/20 00:02, 6F

11/20 01:04, , 7F
啊,對喔,不支援,最近.NET寫昏頭了.. :)
11/20 01:04, 7F
文章代碼(AID): #17GIA2Kj (Flash)
文章代碼(AID): #17GIA2Kj (Flash)