|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
# w2 _- H4 |. b0 L; \" |- I你的Eclipse 是否最新版本呢?
! \# ` [, B+ h' T+ `( N' R' K3 E1 v4 w
) B1 P* |- F( a; Q; a: j
原帖由 rory 于 2009-7-25 14:57 发表 2 N" R0 C8 f2 r5 [( E# N. W5 I
Hi,樓主的BLOG是我經常去的,好東西呀. % Z0 p, ]) P/ I; g
好东西就多上便行了
3 k. c4 f! w3 @# l- P" ]/ X" a) K* @7 N" Q. A, R/ O
0 [# v) j2 E r9 S
原帖由 prenewbie 于 2009-7-25 18:43 发表 : a( w2 i9 n- v- l# A
LZ,在你的blog上留了言,请教helloworld的问题( B1 @7 j, v5 m, j; W
% Y0 S; @1 O. f3 \
想在helloworld这个例子里多加一个button,tap一下就减一个数
& i- ]: i p+ @; c; b于是在first-scene.html里添加:9 i5 h4 E" t! C* a% b& S2 B, ~
4 J% a1 I+ T' l6 K$ }6 g- \1 O5 t2 [3 F, F; |7 y U3 Q8 C% @; L, Y
在first-assistant.js的FirstAssistant.prototype.setup里添加 ...
5 g! P* |, d" s, L+ z沒有任何问题尼, 你做错了什么?- function FirstAssistant(){, I0 `- v: y5 u! ^7 G) B5 k
- /* this is the creator function for your scene assistant object. It will be passed all the
% C9 u; c. ]8 ]; I5 N -
/ l r* ] H, F - ( f; J2 a( B9 O. W
- & [5 Y% L( b* P+ w; H0 n" Z$ @
- additional parameters (after the scene name) that were passed to pushScene. The reference
$ O+ Q, D+ T/ X3 T: H -
, M/ B6 B9 K6 {; V - X5 w0 K4 L8 O2 ~% E
-
$ u8 K, N. t |# ~; n* c - to the scene controller (this.controller) has not be established yet, so any initialization
8 m5 t% ~& K4 X4 a A - , ~4 b8 Q" ?4 j$ B% E! n$ _# X
-
3 L. `7 M' K: N( G- a5 H - 9 z2 a5 C% K' S O d* y
- that needs the scene controller should be done in the setup function below. */# ] `/ Y, p6 n( N. R2 B+ M) I
-
1 N7 d! A \$ f6 z5 `# B9 ~7 ] - }
0 M8 {/ F' X# H0 A( i7 T - : ?6 @) B# Y! Z: l3 e$ \& A! C
- FirstAssistant.prototype.setup = function(){" _2 O5 |- W1 y; D( |% I0 T
- . t# s: _ C. k# b! x, C
- // set the initial total and display it8 p( C7 N5 p t, N' B
- this.total = 0;
8 F! L5 g+ U/ I! j/ H6 Z2 v - this.controller.get('count').update(this.total);2 J" [ Q# n0 u& K" H) n4 z
- 7 M, t$ i0 u; z9 g4 ~
- // a local object for button attributes6 Z* n2 K7 ?8 e" A+ h% Y$ L( I5 n
- this.buttonAttributes = {};$ W6 K! s/ I1 \/ b! g
-
- p/ S8 k& m ] ?% _& ~ - // a local object for button model6 `; f: E' k+ t
- this.buttonModel = {- P7 X' s. ^8 ~" `5 x5 g+ n
- buttonLabel: 'TAP HERE',* ~ u5 v6 V2 z3 u" H$ o/ a8 A4 g
- buttonClass: '',( n9 Q0 p" S6 V% w1 ]; _! T. ]4 L3 b
- disabled: false
3 K$ [8 C* b3 ? ` - };1 k$ i% P1 c4 n$ j* Q% l
-
; a& p' Q B% i; ^& J - // set up the button
" l. b" ]/ b5 ~# P* ~( y" b - this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel);
' S s L$ }; P+ V( S& q, e - // bind the button to its handler( E6 J0 n9 d+ i. ^! a1 D
- Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));
# |! y" ]9 J6 J! w2 w7 [! b - ' u1 V" l3 t3 u' f8 I% _1 {
- this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {
- ~( g1 `' e7 t* X' h9 K: d. o5 H - buttonLabel: 'Decrement Down',
+ b( B6 H8 I: i - buttonClass: 'negative'
5 \* G, x& y7 C% } - });
, d* `8 o! r: j# ~4 N9 f# ` - Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));" }, X) P5 B# {$ _
- }
( P/ p8 _5 R! I; Z* V `1 U( Z - * q2 x. ]3 w" x4 i$ m) P# |' N
- FirstAssistant.prototype.activate = function(event){/ V& O( P, y& s- `. o- H
- /* put in event handlers here that should only be in effect when this scene is active. For
) w- Y" Y* R/ G* X9 S+ T6 \ - 3 L) Y1 ~2 U1 B/ T
- example, key handlers that are observing the document */
" M- F0 Y$ _+ I' Z. P+ Z, w; K2 d - P% J- U9 W. A
-
& {# p9 i5 g( A" o& ]6 u/ D- f - }
" ~0 O/ M* u. _: }% b- N - 8 L. Q6 ]8 L4 \# F5 F, x4 u
- ( F7 P4 F! P" P6 ^
- FirstAssistant.prototype.deactivate = function(event){: D' @$ |5 P- A |3 T
- /* remove any event handlers you added in activate and do any other cleanup that should happen before
6 Y4 s2 X8 {9 x" I3 D' b$ D1 H -
8 P& e1 S2 M& n) ` -
, ~4 s+ _ Q5 ?5 q6 e5 w - % a! b: k% v0 |1 a& ~$ W
- this scene is popped or another scene is pushed on top */
! ^' U8 v, m' Z+ G, `3 m6 E - 2 E. a+ m) S k, L% B; C; ^6 ?) y
- }0 a* X5 y/ D3 W6 X7 r3 Z, ^
- " T L% g$ E$ f/ g1 L$ \ K
- FirstAssistant.prototype.cleanup = function(event){
2 O/ w- C6 f( D& t/ B - /* this function should do any cleanup needed before the scene is destroyed as
. c4 g* D. |. S; ^, H - F, W9 t% P8 t# T
- 6 h1 }& l- j3 r: K4 b; G
- : V" O2 g( B7 j9 x' I8 T+ U. a4 p
- a result of being popped off the scene stack */* _2 n* u0 @5 Z! M- {. v' s
- " K6 K3 ~, z5 ]% g3 X) L0 G/ X2 W. I
- }2 Q/ p8 q: G- |+ K0 R3 i) |
: T6 _' g: f4 K& y' ]- Y- FirstAssistant.prototype.handleButtonPress = function(event){ C+ e" B7 F0 @& Y; K4 L& R/ A
- // increment the total and update the display/ w% j( G) _$ S# r+ ]7 ^; |* M
- this.total++;
# l( x$ l8 X2 |8 O h! X - this.controller.get('count').update(this.total);6 Q. w" O7 z8 Z4 B6 x6 G( K
- }
# a. H5 `: M) V1 D# B - 0 }* i( F# X5 A, I8 ~" V9 ~/ l E5 i
- FirstAssistant.prototype.MyButton2 = function(event){0 g+ O, M% t' q
- this.total--;% n' c) Z2 j r& p
- this.controller.get('count').update(this.total);
7 y* V" d! `" y/ ?# H4 K - }
4 h" c* a2 _3 F+ w' @3 R
复制代码 >>星期六, 日要出街玩, 未有时间更新.
; D- j/ q Y0 E& E6 Q0 G6 N+ `/ w2 H+ L: @: X. V: q z
[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|