|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
: M, K3 a4 h" J6 Y7 g你的Eclipse 是否最新版本呢?
( b# Z' l0 h+ x7 p# B k7 f2 \0 `% P& Z1 j; ?) C
. ?/ I3 @! J* k7 G2 [0 D原帖由 rory 于 2009-7-25 14:57 发表 + w! Z. [9 x, r( [" Y5 E( @" e
Hi,樓主的BLOG是我經常去的,好東西呀.
' p3 f- I' u7 ^: C3 n6 _( ]+ F& C0 X好东西就多上便行了
) P7 S [+ e0 m. ]" g& H" |. @6 H9 \/ H- a+ q1 K( `
5 m( K' F2 }" D4 Y2 N. f1 \原帖由 prenewbie 于 2009-7-25 18:43 发表
6 f/ N4 k6 s |, }! U: ELZ,在你的blog上留了言,请教helloworld的问题
( I$ x+ h8 w; @/ ^7 N. s6 c6 h) K. J0 c
想在helloworld这个例子里多加一个button,tap一下就减一个数2 D/ }4 x1 D( b' N
于是在first-scene.html里添加:. U4 G8 I( k" @+ y2 r
0 o) z2 Z( z ^3 B7 ^3 n* Y
* J$ D# q9 z' G* E
在first-assistant.js的FirstAssistant.prototype.setup里添加 ...
; [$ L9 l. v: n' q1 W沒有任何问题尼, 你做错了什么?- function FirstAssistant(){
7 _7 y, l9 J! j% u - /* this is the creator function for your scene assistant object. It will be passed all the
, F: ^- Y- l( C% Z; ? -
. R |$ F9 D% b7 `. J9 ~ -
3 E3 t0 p- [- q+ f/ k9 A - " G& w2 T- }8 i* s
- additional parameters (after the scene name) that were passed to pushScene. The reference
$ h' }& y7 L8 r" T7 a) [' f, Q -
+ ~1 ~% s% _' Q) ] -
0 {! C5 h. K) B9 } U6 ?! J( k - 2 A [$ N# }7 J) d" [# u
- to the scene controller (this.controller) has not be established yet, so any initialization V6 r# t7 S) b; d9 T4 R
- 0 C: @, U. W& y/ X
-
9 J6 y5 I0 J2 b7 O - ! I$ d" z+ S ]" I+ B7 Y
- that needs the scene controller should be done in the setup function below. */: ^: g9 e1 B" B k4 J4 e9 R% Z1 B; a
- ) @+ P7 D1 a M4 W- k
- }
8 Z( c7 D! G7 J/ \& q3 [ - 6 ^# }2 Z0 ~" s% v) Z* a! r. i7 I9 M$ j
- FirstAssistant.prototype.setup = function(){
( j$ A* Q4 N! F3 l6 b - 4 d# Z" p# [- t* e
- // set the initial total and display it
. G# k; v6 n- [8 s' _ - this.total = 0;- W6 g$ W; v# p5 G3 U) R
- this.controller.get('count').update(this.total);
0 w0 {% r$ o4 q9 ]" q9 `* J - * H' N% m4 a) p
- // a local object for button attributes
/ q+ e1 F$ Z) f) T/ n- Y - this.buttonAttributes = {};
0 K% x5 b3 |8 \0 H/ ~* w" R$ t -
) L( {3 m4 B. b& O2 v - // a local object for button model
) |2 k4 k9 V, C5 j j8 h0 A - this.buttonModel = { j4 `) X4 ]! w2 P% }
- buttonLabel: 'TAP HERE', Q) r" k, B6 c: x- C: n1 p) l
- buttonClass: '',2 z; ^ @2 d0 D! r. e! ^: D
- disabled: false6 i# P) X+ P/ d) D
- };# t% n* l2 Q6 K2 c/ ^9 L
- 8 V. N- a' E1 I8 K8 t
- // set up the button0 a* c) B% t) m% q' g' U" ]
- this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel);6 ^; V, U4 H& ~8 w5 ^) A
- // bind the button to its handler8 K" w. O3 N! [, Z
- Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));" _* g% W. [' Q5 `6 u; ]1 Z7 q$ G
-
$ y, f& O* D+ N) V3 I" [7 Y. W2 J - this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {% E8 T8 }* [) F+ s, U; [
- buttonLabel: 'Decrement Down',4 O# J8 p: S& D% t
- buttonClass: 'negative'
+ X, j* c" p; ^+ X5 B+ _ - });- E% F0 Y) a/ \3 G
- Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));
e/ ?2 b9 ]. v3 z9 A( K8 ?6 | - }- J; c4 r1 c; f" `
- $ X0 i2 S5 s, D1 b
- FirstAssistant.prototype.activate = function(event){
! j) U! Z) Q5 i; M: F6 A% d& v - /* put in event handlers here that should only be in effect when this scene is active. For2 x' T6 A2 o( l( P
- 2 K9 h G7 a' L" ]% l
- example, key handlers that are observing the document */
9 D8 a' ^! A2 M -
" h+ Y3 a) U6 u/ U: ~/ P; J$ @+ m - % }/ S4 ~& D' L/ ?
- }
6 Z6 U- ]# c: S4 P+ u' p
; z/ v/ [0 M+ u/ ~) Y- e- C+ [3 j; k
, b, u$ ?1 H+ G2 }3 O- FirstAssistant.prototype.deactivate = function(event){7 y7 t" J$ X) w6 \
- /* remove any event handlers you added in activate and do any other cleanup that should happen before$ W! B$ N; ?5 J0 m6 O. f2 o. R& z
-
( y) \! G! ]3 I( W -
- z- G' j; p4 P/ C! c -
' {3 [+ G, D+ A& s8 Q, e& R8 ~. ~ - this scene is popped or another scene is pushed on top */4 m& t6 h; N7 I
-
+ T% U# P9 M3 w& d2 w h; ^ - }) ^+ j/ G$ Z1 Y" e
8 ?5 M& x6 G* L- FirstAssistant.prototype.cleanup = function(event){
$ t; A* b6 r0 i o4 C9 ~ - /* this function should do any cleanup needed before the scene is destroyed as
! R* a& u8 m( g5 r; ` -
" m, n) K. g0 D+ v! r7 i! K5 l: h -
) I/ R" s5 ?0 k" j. d. ]3 _ - ! v8 U5 `, w3 j- t5 W! W5 z6 b
- a result of being popped off the scene stack */1 w9 V7 D0 i% F0 [6 [; t( ?$ Z) C, x
-
: K4 f1 ]4 ?3 J/ q - }7 p; E q* k" Z J, c
- H6 ^2 a* r. G1 W. e' E- FirstAssistant.prototype.handleButtonPress = function(event){* _, x+ j& c0 m# G& n5 C
- // increment the total and update the display ?1 [' z+ R* d# y$ ?. D" g
- this.total++;
1 w$ N# ?9 Q( p* @ - this.controller.get('count').update(this.total);
. _/ s/ I: D1 v8 c! U/ t! ` - }
4 N! W8 ^0 _# a* T) @" h3 S0 D$ l - , t9 N# [ \1 d3 v2 a$ K0 A* ~
- FirstAssistant.prototype.MyButton2 = function(event){
9 z* r( w) C2 A5 ~8 D5 p. u0 ^) j - this.total--;
$ I `7 V$ O8 v8 W8 @; y5 R - this.controller.get('count').update(this.total);- h8 `( B) ]- h# f. A1 d
- }9 v8 X6 [/ m1 x
复制代码 >>星期六, 日要出街玩, 未有时间更新.. q# `" _' s8 H% ^
( a+ k7 a3 g7 l6 t. j1 _7 Y+ z[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|