|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
: s# }. u, J+ n- T你的Eclipse 是否最新版本呢?
@6 v; S( [" ]% E% I# @+ _2 B: z) M5 f7 w/ _
9 O( `+ A1 c+ T( I' R# n
原帖由 rory 于 2009-7-25 14:57 发表 
. _$ [+ {9 ^; |4 E- \* M5 M7 ]Hi,樓主的BLOG是我經常去的,好東西呀. ( T& I8 t/ _7 K! z5 O) a2 A7 l% m& }
好东西就多上便行了- z- z7 z( M o
0 d6 I: ~ m* {1 m8 i1 E. _* `
/ A. B% w# n, L原帖由 prenewbie 于 2009-7-25 18:43 发表 ' G- J* ?* R$ z/ J# |
LZ,在你的blog上留了言,请教helloworld的问题
/ o9 w5 q$ U2 k* h4 r7 P) K, q% f3 u2 `3 \4 r& Z1 W! |
想在helloworld这个例子里多加一个button,tap一下就减一个数5 T0 N, N+ l [1 Y
于是在first-scene.html里添加: v( ]- C! E3 V% K7 d# |2 o! f; Z
9 @ `# \! }0 `2 c6 d+ e. z* P- U7 ], @1 i1 m! p
在first-assistant.js的FirstAssistant.prototype.setup里添加 ... # P; q5 K* s$ A4 Z9 D1 j
沒有任何问题尼, 你做错了什么?- function FirstAssistant(){
0 ]( D& G v; ~) `' u - /* this is the creator function for your scene assistant object. It will be passed all the 3 h) o& q9 K0 g t: z
-
( d+ c* |3 R" s+ O -
' m6 j. t; s! H/ @8 V - ) W4 a& o" o- X2 L! ?% W5 k
- additional parameters (after the scene name) that were passed to pushScene. The reference
5 B s! s/ b; v: m f. _! \, p1 U! q: s" W4 z - * R5 G2 C3 z: e/ J L7 y; d- V
- 6 A( d, Z& g* P/ O
- 2 A+ ], \2 J& H2 h6 ?" H8 m
- to the scene controller (this.controller) has not be established yet, so any initialization
/ V/ m2 S: d0 ?7 N; U& Z -
" U4 V4 ~6 K3 [3 q H - 5 s( r+ P2 e% d; }/ Z" X
- }# F# a. `/ B" b8 U
- that needs the scene controller should be done in the setup function below. */
& T$ u5 g/ |# `7 b - ) O1 z% q8 U9 o" Q+ j' N
- }' y. `6 b5 Z/ }8 x
- : S, }7 \; R# p& W. l. M, a- Q
- FirstAssistant.prototype.setup = function(){
7 q$ k! A4 J3 d: j# Z5 c" l- B) B
0 ]8 O7 V2 N4 A3 a- // set the initial total and display it! a6 Y8 x/ I( j
- this.total = 0;
* Z& H: V( N! ^% C - this.controller.get('count').update(this.total);
. y( H3 w+ O8 H - 9 |( g! ~5 B8 R+ D& j+ v
- // a local object for button attributes
- V1 p- ]# q- `0 j) M& F" u) @9 ^ - this.buttonAttributes = {};
a5 _, X8 b' q -
* r7 ~% O$ u* c8 g6 l - // a local object for button model9 i) c5 k1 j: I8 P1 ?
- this.buttonModel = {. P) x6 \0 ]: u( l; c& V; P5 [
- buttonLabel: 'TAP HERE',+ m" A" I; D) y$ k% m" y; `/ e7 m4 B
- buttonClass: '',' F5 s" d* w# d
- disabled: false
# [/ l3 B; D1 T- p9 _7 @ - }; H/ u! `, b& z+ @
-
8 a9 F. A% p% ~3 P - // set up the button
2 j8 l3 Z/ w" m0 d( i2 n - this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel); \% i0 b" p- R9 a l3 U% c0 }
- // bind the button to its handler
% _: T* H/ \% }& o - Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));7 U) ^* K3 F2 f N2 q% d6 d& ?
-
+ w/ |: W+ M5 Q/ a' | - this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {9 R f8 I3 @, G+ I* [+ W
- buttonLabel: 'Decrement Down',
/ Z' i" f+ H" B8 S - buttonClass: 'negative'
6 a: G+ T& X6 _- u - });
6 J$ ]: c3 C* \% u% s: c5 T" N - Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));1 D, b- x3 o `
- }
+ C' `+ s) y; n4 q% T: \
1 A- R9 s( o" A; U- FirstAssistant.prototype.activate = function(event){
0 G9 m) M. V8 {# y - /* put in event handlers here that should only be in effect when this scene is active. For- S$ A7 ]( h' ]. ?1 q/ t2 _
0 X0 b! V- q$ B6 u, E0 {- example, key handlers that are observing the document */
" a) O% P; w, y0 ~" }. E& u -
& ?# f2 k/ e6 E- P7 n - ; i& k, s& A, L0 Z3 f
- }9 X8 {3 [, S! z$ @! v
2 d* E9 ]/ e# W) Y9 @* {/ f1 N
/ C' D5 j4 i1 T' g: U- FirstAssistant.prototype.deactivate = function(event){* Z$ o2 h9 x0 D+ o* H6 T' ?
- /* remove any event handlers you added in activate and do any other cleanup that should happen before
% h; n; ~# N# z5 D2 w4 u" T* r - / ^/ _5 ^$ M. s
-
, e2 o* P. [" x - # \: Q. W4 k7 [& P3 l
- this scene is popped or another scene is pushed on top */* D" F4 o) t/ k u
-
, b4 C% o5 k w+ V - }: Z. e4 {5 _, U6 d( {
2 {- o' p. l t* ^) Y5 m9 B1 R- FirstAssistant.prototype.cleanup = function(event){% F4 W# K+ }1 {: c, [3 J7 r
- /* this function should do any cleanup needed before the scene is destroyed as ( @( i# L" J- o" C& a3 b, k
- # A0 N8 o3 _" ?- U9 k
-
/ i4 W- ?* N- U! ]& ]+ G3 W -
3 f1 W9 j0 v8 m' I - a result of being popped off the scene stack */
. G# x5 u# S! E: u -
6 b* G+ k B* ?$ R2 a( P7 v8 i- k, e - }2 B9 q& t3 K; D I) j
% G3 F" @" y3 D9 F- FirstAssistant.prototype.handleButtonPress = function(event){
; c9 e4 G5 e/ |! i6 W' i - // increment the total and update the display
7 e/ `, N& u j - this.total++;
! v ^ s) }, J" {5 y - this.controller.get('count').update(this.total);
* \8 ^4 V. t' V. w1 [6 C - }9 R8 t$ F3 h* ^# r
- # J8 @* J9 J2 S- q4 ^+ j
- FirstAssistant.prototype.MyButton2 = function(event){3 ?' i0 g( W8 i
- this.total--;
7 v' Z8 b6 I& Y9 V - this.controller.get('count').update(this.total);$ W3 D9 w! f1 {7 h& f1 z
- }6 s6 L6 O. K2 X3 x7 R
复制代码 >>星期六, 日要出街玩, 未有时间更新.
' V* t7 ?$ z) q y# R3 J' M$ t. X3 j! E I0 B/ }
[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|