02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

195 break;<br />

196 case 2:<br />

197 avatars_so.data.name2 = "";<br />

198 avatars_so.data.used2 = false;<br />

199 avatars_so.data.x2 = avatar.org.x;<br />

200 avatars_so.data.y2 = avatar.org.y;<br />

201 break;<br />

202 case 3:<br />

203 avatars_so.data.name3 = "";<br />

204 avatars_so.data.used3 = false;<br />

205 avatars_so.data.x3 = avatar.org.x;<br />

206 avatars_so.data.y3 = avatar.org.y;<br />

207 break;<br />

208 case 4:<br />

209 avatars_so.data.name4 = "";<br />

210 avatars_so.data.used4 = false;<br />

211 avatars_so.data.x4 = avatar.org.x;<br />

212 avatars_so.data.y4 = avatar.org.y;<br />

213 break;<br />

214 case 5:<br />

215 avatars_so.data.name5 = "";<br />

216 avatars_so.data.used5 = false;<br />

217 avatars_so.data.x5 = avatar.org.x;<br />

218 avatars_so.data.y5 = avatar.org.y;<br />

219 break;<br />

220 }<br />

221 avatar = null;<br />

222<br />

223 }<br />

224<br />

go<strong>to</strong>AndS<strong>to</strong>p(2);<br />

225 Selection.setFocus("entername");<br />

Listing 23.1<br />

Once we have got a remote shared object we can get and set the data in that object. Line 19 shows<br />

how by reading the value of the shared object data value ‘used1’ we can decide where <strong>to</strong> park up<br />

the first of the five avatars.<br />

Lines 50 through 66 update the position and names of the avatars every time a sync message<br />

is sent from the server. This occurs as data s<strong>to</strong>red within the shared object is modified. In this<br />

instance we simply update our avatar movie clips with the information. This callback function is<br />

invoked when we connect <strong>to</strong> the server at line 69. For each avatar we define onPress, onRelease<br />

and an onReleaseOutside functions. The ‘onPress’ function is defined between lines 72 and 87.<br />

First in line 73 we test <strong>to</strong> see if we have already defined an avatar, if so then we must disconnect<br />

before we can select an alternative avatar. We also need <strong>to</strong> test if the avatar is available, in which<br />

case the value for the shared object used parameter with the index of the avatar will be set <strong>to</strong><br />

true. Assuming that we are currently disconnected and that the avatar we have clicked is available,<br />

368

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!