|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
r$ n7 }4 X4 E你的Eclipse 是否最新版本呢?# W; d* W, |2 L* K# x4 ~
+ _: }4 p* E9 {. Y1 ^ M$ h( i
$ z% N" k% g* U8 m& E& Y5 r+ j0 p原帖由 rory 于 2009-7-25 14:57 发表
( m7 s1 g. b3 r8 H/ g# r+ OHi,樓主的BLOG是我經常去的,好東西呀. * Q. y! [) ]$ v/ v h
好东西就多上便行了
2 x6 r0 g P6 }5 j1 Q
, Y' d. b5 @% b8 e6 \6 |# K% s8 R7 u( V9 b6 S& O- O
原帖由 prenewbie 于 2009-7-25 18:43 发表 S4 J/ h- N6 q B5 I
LZ,在你的blog上留了言,请教helloworld的问题5 @2 S8 [0 ?* N) o% h
8 @& b: D' v& J9 A7 n# _& s
想在helloworld这个例子里多加一个button,tap一下就减一个数$ G% o$ x4 q0 q3 O+ `7 V
于是在first-scene.html里添加:
6 V0 j; `& w1 Y3 w) @5 H1 K: ^& M9 w; h
( x1 B; M" R! V4 ?7 v4 s; l% l
在first-assistant.js的FirstAssistant.prototype.setup里添加 ...
* u& ^* C" p% _, Y6 E/ ^沒有任何问题尼, 你做错了什么?- function FirstAssistant(){" x+ b' h% r% m' F
- /* this is the creator function for your scene assistant object. It will be passed all the
) G9 p- u' q) b8 C8 t: Q - ; a& I8 g: D3 R5 [0 t! P
- / r: S4 k& J. N E; [! g) [, V$ U
-
$ D+ c+ H. |& \! }4 u6 R - additional parameters (after the scene name) that were passed to pushScene. The reference
$ H6 p. d! J j7 I+ \: w# o6 Z - $ K3 `; W: P( P, \5 z
-
/ p$ P) o& h5 l( v! q9 A( I - & C9 A4 e, c! c7 l1 E8 \$ J$ w
- to the scene controller (this.controller) has not be established yet, so any initialization
- J9 o& j* B! R3 {+ e4 Y - $ s3 b6 F6 V( u! {
-
! O; f* T6 x0 c9 d' R9 t -
. h4 J8 w$ A7 p; g - that needs the scene controller should be done in the setup function below. */
9 d1 P: U) o3 D0 a5 i - , H" z9 ^+ |- x( b! [& c$ T3 ?/ T
- }
8 L! Z' `* f' J1 Q( t0 p; b& H
1 _$ J( q, {- Q r- s- L8 H+ m6 g# a- FirstAssistant.prototype.setup = function(){. K2 M" r( V% \3 W! _ P0 t% p
9 g% c9 r4 w! N" |0 S# o- // set the initial total and display it3 p0 m- D7 M) b* f# F
- this.total = 0;
- m! K' D. @; Z, U! f" l - this.controller.get('count').update(this.total);9 X7 [8 Q4 N% \8 f: q
-
$ f& J9 I P* A! |/ j5 g3 Z+ O0 j - // a local object for button attributes
# m6 u& q& z, |: G% v) E - this.buttonAttributes = {};! |( j# X9 O, }' X' |
- * B6 Z4 r3 j) B4 `7 [& d: Q
- // a local object for button model
; I1 ]9 G" Z- k9 K& p3 F T4 Q - this.buttonModel = {% A d& R* W4 W, \% E& y2 D
- buttonLabel: 'TAP HERE',4 b' `# E" }0 J0 M- ?
- buttonClass: '',
- D1 Q8 L. u& J E - disabled: false b% j! ^. l) m$ h/ P3 c
- };' K. f' K! F; V7 G/ t" j4 A& {9 n
- * ]- Q! p1 _7 m% v& m) v1 ]
- // set up the button: h3 {; R0 S. F I' L5 c
- this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel);3 t: Q& |5 k- u" o
- // bind the button to its handler9 e- _! B( F/ Z
- Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));& Q1 ?& M0 D$ f$ F( |* M
- 2 ~9 i8 j; n$ |( F
- this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {
2 Q" |! `; s5 k - buttonLabel: 'Decrement Down',4 E! Q. Y: O7 C* A' P' B
- buttonClass: 'negative'1 R3 C% G. U9 @
- });
% d# a) N# T/ p: Y* k/ ]6 S: q2 ^ - Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));
( `+ H4 X. q. F+ |1 I9 q - }
9 E# A- v7 L Q! r( _' L
! |- M: S1 G B9 ]$ \) A; _- FirstAssistant.prototype.activate = function(event){$ ~7 Y! |+ q: m1 z5 O6 a U! c$ a
- /* put in event handlers here that should only be in effect when this scene is active. For. w% x: r {, ?: i' P u2 Q
Z2 y; K/ h, M) k4 b- example, key handlers that are observing the document */6 I @& b- v, ]: l- ^8 Y% k
-
6 z$ ?" C% f+ ^" s4 Z" l - # r" t u- s, b4 i
- }: m, w% d- o- e
6 h) D, {3 v E; u- " k, _: k% [! |! Q4 }
- FirstAssistant.prototype.deactivate = function(event){) L$ ?0 N( D6 v+ y' d# w6 Y6 y
- /* remove any event handlers you added in activate and do any other cleanup that should happen before
0 z( S1 t: v' K3 f8 e: N7 s: q - ' b" R7 M1 x0 w; a- k: h
- 9 Z9 U; ]0 s% {8 ]1 _% u/ P- E) e
-
/ [7 O3 f- w2 _/ o0 h9 S. L - this scene is popped or another scene is pushed on top */
" H, A) _% k% a, V -
8 I; m; p- e3 g2 @) K, v3 ]5 k - }: \( B. c* J1 ^$ O! {
9 w: D5 o2 i8 V- FirstAssistant.prototype.cleanup = function(event){
1 v. F! [* w1 p A - /* this function should do any cleanup needed before the scene is destroyed as 0 o7 y( F$ B+ v# f M( R8 ?7 R" x
- $ w8 s# ?, |3 m* G0 W
-
- `% _* s- X$ {" B" w9 X - 6 d8 T1 q! h. E6 C
- a result of being popped off the scene stack *// ]5 }/ E* v7 |7 G
-
* z+ R3 S( L }: O" ^& f f - }( \, T$ P# F7 o* G
! i8 x& ?' B6 j1 G- FirstAssistant.prototype.handleButtonPress = function(event){) Q) U- r: y( V% v* K1 G1 C; s8 r
- // increment the total and update the display
8 H; o% f9 z. k$ L& Z - this.total++;( B/ A# Y. B3 G- P; e
- this.controller.get('count').update(this.total);! l) D( T) q" U
- }
( A+ j# H- r* R# {' P, E* J - & E& y. H7 Z# q7 c$ t
- FirstAssistant.prototype.MyButton2 = function(event){
# l+ U |6 H) q' u" F x - this.total--;$ x$ b& `! ]/ d. r/ y
- this.controller.get('count').update(this.total);( b) C e5 ~ ]0 G, V
- }
* i2 @' S1 P3 w5 D3 O
复制代码 >>星期六, 日要出街玩, 未有时间更新.
0 u8 |3 {+ X6 J, y. P- v; }, T7 q2 k3 {! u/ l( t% }6 c* F
[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|