|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
* f' C+ g6 M& X* n" a' Y7 \$ y$ f
你的Eclipse 是否最新版本呢?
$ c8 Y2 ~% U9 x9 c" _8 O% `" Y5 u2 e- z
" N6 X! p* u2 ?$ k" k) u
原帖由 rory 于 2009-7-25 14:57 发表 / P# E2 W& {, K% L* u
Hi,樓主的BLOG是我經常去的,好東西呀. 7 M, A1 V( N- s
好东西就多上便行了
0 \/ J* d7 Y* ~( @% q' s
; Y G( w- }, F- I5 `( o
$ U9 l: a! h6 x1 `( R原帖由 prenewbie 于 2009-7-25 18:43 发表
( L, z3 y n8 v/ @" u4 G& [6 s- ZLZ,在你的blog上留了言,请教helloworld的问题
' o& Y9 l/ q% q$ o( R. B- _; _* S9 T% Q! o0 z/ F: J8 L0 {
想在helloworld这个例子里多加一个button,tap一下就减一个数' W1 s0 w; t# {# a5 K2 S+ Y
于是在first-scene.html里添加:
* W* [0 a2 Z8 L/ Y1 D1 _
9 j2 |6 a. B# a$ F* }; | U/ d. K1 o' o7 C8 v- t$ w
在first-assistant.js的FirstAssistant.prototype.setup里添加 ... 2 L, I! j$ G2 B' R% k
沒有任何问题尼, 你做错了什么?- function FirstAssistant(){
9 j/ L7 X! {# l! X - /* this is the creator function for your scene assistant object. It will be passed all the
) t# T0 @% M' w7 d% v& A7 V8 {, F -
) F3 j' ?4 V8 k: m - : H- j) K3 {! I% D! n) ^
- $ G3 Y0 R6 ~6 ~5 A, B
- additional parameters (after the scene name) that were passed to pushScene. The reference% _! I; r- n6 Q( Z5 \1 [2 t' W. H3 o
-
% l# U" k+ g3 i7 t$ ~2 R0 Z+ `" b - c) J) J" Q* n" Q/ Z
-
% P$ r; q$ D9 X- b# ^; i - to the scene controller (this.controller) has not be established yet, so any initialization
) E, ^4 K/ ~4 C5 G0 B& [3 \ -
8 J" b8 X' M2 ?' e -
4 P! M8 O \% N; U9 O -
! g% y2 g; q: f3 Y8 |% Z - that needs the scene controller should be done in the setup function below. */) U; ]; W1 v! \5 E& m5 T# P9 I, D: v
- # s- |; }" h8 x9 U6 Y4 D
- }
( B5 Y8 q. e/ {7 n
5 v# _6 a6 S9 N5 j; l: y, W3 `- FirstAssistant.prototype.setup = function(){
' ?' u$ D; G, y3 m) s
! |8 p' M' t$ G- // set the initial total and display it- F8 v/ l7 j' z5 D
- this.total = 0;7 b' H' T7 o( ], f* L2 b
- this.controller.get('count').update(this.total);2 E! [6 b5 n* @0 D9 V
- 8 b# I" u6 ? [4 l8 W# @. A
- // a local object for button attributes+ X3 N( d4 j" w
- this.buttonAttributes = {};
& l; o4 A! a' w - % \. {1 O+ t8 O1 v
- // a local object for button model
+ S8 d1 B% R* S4 r. o+ [ s1 A - this.buttonModel = {
9 J. _) \% T2 O( _2 M - buttonLabel: 'TAP HERE',& W9 H& | l' L. i3 P
- buttonClass: '', r3 h9 p2 F, { F* E
- disabled: false
( n8 E) n. V4 _; _ - };* [. ]5 b. l% p9 }) A" K- X, l
- 3 | t( A1 G1 s
- // set up the button5 J' b. }3 Z+ L9 a$ |( q& k
- this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel);
9 e* Y N1 o" Q5 ~0 E; w k - // bind the button to its handler
C: q4 c9 e% y7 u2 Z4 | - Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));
* P/ Y7 Y% v( [8 }0 l5 ?' T - 3 G/ [8 S" ? _4 l: `
- this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {( _6 `& e+ a. g, D
- buttonLabel: 'Decrement Down',
$ k w6 B" A- s M2 L9 h - buttonClass: 'negative'
2 B6 E3 C- g# b7 L6 ]/ S6 a& } - });9 v+ u9 u8 u% G7 y$ W, m
- Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));& M! j& [1 \/ w& s" P( d1 V
- } m' p& `5 }8 }; N7 x+ @( N
" M6 {5 [" F8 S" f- FirstAssistant.prototype.activate = function(event){- ?4 [/ D$ x$ i6 }$ `5 p8 r: }# f
- /* put in event handlers here that should only be in effect when this scene is active. For9 L: \1 o3 j5 v1 g
- 9 e& u7 i2 J9 a' _: F; r7 L
- example, key handlers that are observing the document */9 j. \- d" f6 Z% A+ R' e. y1 p) {
-
6 [ D5 a. ~7 L3 z5 H* X' ]- J) | -
( q. @8 i! D5 o _$ I+ ~/ J# M - }
7 X, z/ H5 U2 }" j
( E1 J3 f4 _# X5 _% F; G) T- ; Q, V/ z6 y8 N7 \
- FirstAssistant.prototype.deactivate = function(event){
9 [2 F2 q% P% D) ^- @ - /* remove any event handlers you added in activate and do any other cleanup that should happen before
5 i% z; j: o/ V" ?8 {# @1 ]6 ^5 T -
+ G3 G' A, w2 _* _- B* g, J - 9 |+ G9 ~+ z6 J- I
-
" M+ }& J9 h2 K) \- d - this scene is popped or another scene is pushed on top */
9 o& m& ~( V+ a8 @ - # N X$ {; |3 z6 r F1 z7 I2 E
- }
2 D/ y3 J# c5 g+ Q& U - + h# V6 l2 {. [7 a+ ^7 D; ?" B
- FirstAssistant.prototype.cleanup = function(event){
" |) X3 z- q/ F( m5 c% w7 ~. h) G - /* this function should do any cleanup needed before the scene is destroyed as # |% j% a/ i8 p$ |& D. C
- ; g+ b9 y y1 G7 |* j
- , B, {) e3 ?% B$ H& I+ [* }7 B
- " a, m( m* C/ P% G+ F3 m1 O
- a result of being popped off the scene stack */
$ r* ?1 d. I3 [8 i/ F - S ~ b2 X% x# V& [
- }
3 H# ?& \; O9 J; E6 M - 6 y/ T( ^ D B# y
- FirstAssistant.prototype.handleButtonPress = function(event){/ `8 {; Y7 w1 U4 }, w d- r
- // increment the total and update the display4 U1 p- ^; c& v y
- this.total++;
/ C( e2 ^' \% [- ~1 H8 u - this.controller.get('count').update(this.total);
7 S; j" D) ]6 H" k - }
" Y9 z& s4 n* `: R) K
% F( n, s# }/ o; T; Z7 o9 C) Y' @- FirstAssistant.prototype.MyButton2 = function(event){% w( F) ?( O# y4 D$ v& B. L
- this.total--;* P. A2 \5 x2 M8 Q
- this.controller.get('count').update(this.total);
. v. w$ j: {& O' q. }' R" b' D2 e t - }8 N. Y+ _5 j9 Z7 d; ` G
复制代码 >>星期六, 日要出街玩, 未有时间更新.0 O# z1 k- d" k, l; O, M
! ~2 `! y- i* F4 m, G
[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|