|
楼主 |
发表于 2009-7-25 21:32
|
显示全部楼层
, L) A. R8 @7 N2 t/ F
你的Eclipse 是否最新版本呢?+ J `3 `7 q" {) U" k( }# U3 Z
0 J: w3 C" f' l5 H
# |& V: u: ^# @% D, O7 s
原帖由 rory 于 2009-7-25 14:57 发表 + B( e) F8 H9 J
Hi,樓主的BLOG是我經常去的,好東西呀.
9 C0 S5 r. F. d* C! p5 I好东西就多上便行了
; k3 k1 r* v) K- k& h9 |( E6 r5 c `0 l& g* R6 B) ^) L
1 ^) w5 H2 J& k, \2 \原帖由 prenewbie 于 2009-7-25 18:43 发表 
q% l, K, [9 U! v$ Y) t3 r0 a7 }LZ,在你的blog上留了言,请教helloworld的问题$ U' x' L" e1 I& H5 R9 v( O
7 x" W% n6 y: z. C9 H% L
想在helloworld这个例子里多加一个button,tap一下就减一个数
& S/ T, Y0 _ i; V6 J( X于是在first-scene.html里添加:
1 ^% j) l. ?6 ?% a
6 \2 x' O8 s1 W: `2 H5 b. C
( @* t1 A0 t {5 g3 Z在first-assistant.js的FirstAssistant.prototype.setup里添加 ...
6 b* @$ \( f7 {! {5 R沒有任何问题尼, 你做错了什么?- function FirstAssistant(){1 Q! M% \& _3 l+ `
- /* this is the creator function for your scene assistant object. It will be passed all the
9 G( o' y7 P* ^: T -
: D8 W" V" l2 [ - . n0 l2 }8 ^9 A% Z5 Q
-
@) m4 G; S* r; Y+ h; I - additional parameters (after the scene name) that were passed to pushScene. The reference
2 H) S: M# G& L/ t* T0 C$ { - & N! P& \2 d$ o6 s/ l3 x
-
$ c, l1 S" B0 z9 X4 O -
, L: ?+ v# z$ m$ U2 b$ ]4 I - to the scene controller (this.controller) has not be established yet, so any initialization$ `6 v2 {( |: O! b- W
- * D2 p# j7 ~% q
-
" V2 N$ }) g0 Z - ; A, d3 t, J5 |, ^2 B8 H$ S' d
- that needs the scene controller should be done in the setup function below. */
# a. _/ A' m# h( r3 n! ^ -
+ @; `& M8 |4 Z - }
( M! w8 `. l) x6 r, E/ \
$ V2 t0 w6 [, Y6 Y8 G" l- FirstAssistant.prototype.setup = function(){
- D* V8 c- L% G! ~
0 C5 U" D# m8 a) S- // set the initial total and display it; A& l) R7 }5 S+ {
- this.total = 0;
v9 |' L) ]! p l, q" {: Y/ W - this.controller.get('count').update(this.total);" _: _! `0 U; E
-
: b* }0 }- K) U) C - // a local object for button attributes
$ O# {6 X7 H& w8 r3 ?2 M - this.buttonAttributes = {};
( k$ u7 j$ k: t) j - # b3 k# U, ^" W9 F' }
- // a local object for button model1 o' [; W& U. P* w! _& y
- this.buttonModel = {* P% v2 d: r7 ~! o: ~" H
- buttonLabel: 'TAP HERE',
( u x/ U d0 Z3 n( l - buttonClass: '',
+ x1 ]% e) P2 V t3 T3 H - disabled: false
( c$ g! T& n) U$ \* z - };
% m1 X1 j0 q+ d4 B; i. ]* ^3 p* p - % B C Q2 E5 U" P; X
- // set up the button; n6 M5 h( Z, F( A* ^! ~& ^
- this.controller.setupWidget("MyButton", this.buttonAttributes, this.buttonModel);2 t3 `" S+ a5 ]! ]3 `& s7 \5 G
- // bind the button to its handler* k! b+ K5 ?& d% ?# x+ a
- Mojo.Event.listen(this.controller.get('MyButton'), Mojo.Event.tap, this.handleButtonPress.bind(this));( C9 d& D3 \: T
-
& P8 B: K) A# }6 R# y; ` - this.controller.setupWidget("MyButton2", this.buttonAttributes, this.model = {
. ~" o( n, t' l7 D1 b; v - buttonLabel: 'Decrement Down',
, K# p+ B0 I! T: z- ~+ i f- Z% c - buttonClass: 'negative'
: ], g: O b( v+ J; d: ~ - });3 J Z( P$ P0 Y) R
- Mojo.Event.listen(this.controller.get('MyButton2'), Mojo.Event.tap, this.MyButton2.bind(this));
% p3 n) R$ @( Z& v; q) `! k/ B - }3 l# I/ D7 V5 G4 N6 Y' v j, J$ m6 f
- 3 y. W$ b8 W( e Z( B# L6 L
- FirstAssistant.prototype.activate = function(event){; B6 h9 S- c! B* k5 P! p/ c6 H5 m
- /* put in event handlers here that should only be in effect when this scene is active. For7 J/ C% G' r# I& t
9 _+ x; c o; R- example, key handlers that are observing the document */1 U7 q G* H7 x( f. f
-
4 [; o) E% |; D. t - $ V4 @% m; x. L4 y9 K6 K# M2 v
- }7 I1 n4 b# C; I9 O1 x
- 5 l/ v, W0 a" O
# O r) _# a! ^, Y- FirstAssistant.prototype.deactivate = function(event){
' l( V- }5 j( B7 z: S3 M' ?% Z5 f - /* remove any event handlers you added in activate and do any other cleanup that should happen before+ [7 w5 B* [' W
- 7 I9 a- W* {: `' [# J
-
9 n2 Z" Y5 X( {/ ~, E2 K' }& y2 x - , x$ i S& E' V3 n5 K/ E
- this scene is popped or another scene is pushed on top */
# p' G! o" |+ k' ]3 g -
, q8 Z8 N! N( J2 J* x$ _, ]* b - }
3 N' x# X+ n) ^+ u1 W% d e0 | - # \$ L! t+ Y0 Q4 O
- FirstAssistant.prototype.cleanup = function(event){ s: J, G5 H3 {' V. y% O) U6 H
- /* this function should do any cleanup needed before the scene is destroyed as
9 e, f) c& Z) d$ y6 U3 f- K' c+ [& g -
% g; x2 s* r `4 g t- F+ A4 m0 ] - " C7 C: U3 Y% r5 F" s$ ~
- / G5 ]/ l: }: v# y% C2 i/ Z$ d
- a result of being popped off the scene stack */
& i* {. Y# j( k& U, P) | -
4 B% z" |% x$ N0 D7 }8 Q- Y4 i - }
" E& R1 k {4 o& H/ S4 i1 b* E( g
0 U4 o$ }5 H1 ?2 i7 ]# Z% T) ^- FirstAssistant.prototype.handleButtonPress = function(event){* s: A5 U9 }, q3 \; V& p( ]$ m
- // increment the total and update the display
. m# d% L5 O( j1 Y - this.total++;, e) _, t0 S& H. z1 q
- this.controller.get('count').update(this.total);1 r5 [' w1 v- r* H( ~7 S+ K
- }
/ k' ^# ~3 X) Z' O0 f) G E$ Q
' k& ~% n; a. O1 |6 A6 k, D( W' Q. F- FirstAssistant.prototype.MyButton2 = function(event){
- f6 M, A: h+ r. y! v5 t' G - this.total--;
- P. a" ?/ s- {" ~ - this.controller.get('count').update(this.total);
; F! @2 N o: U0 G - }. u" Q$ q+ t- x8 K
复制代码 >>星期六, 日要出街玩, 未有时间更新.3 q3 Q2 B! j; [5 R
: [; k1 Y& W* n" g$ E8 w( G[ 本帖最后由 tedwong 于 2009-7-25 22:06 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
×
|