Quantcast
Channel: ZombieFlambe
Viewing all articles
Browse latest Browse all 10

AS3 BackboneJS-style Model Experiment Pt. 2 – Target Value Model Events

$
0
0
As we saw in AS3 BackboneJS-style Model Experiment Pt. 1 (definitely read through that first!) I created a BackboneJS-style model for use in AS3. You could listen for any change on the model, or for a specific property on the model to change. This got me thinking though, let’s go back to my previous example where you have a “mana” property on the PlayerModel changing, and you have 6 Tower Icons that are listening for ‘change:mana’ and they’re having to check if the changed mana value is greater than or equal to the cost of the individual tower to know if the Tower Icon should “activate” visually and become clickable so the player can place a specific tower. This means that every single time that single property changes, the Tower Icon is having to do a check to see if it should activate or not. Now, as we saw last post, that’s a lot more efficient than just getting a “change” event any time anything on the model changes… but, why can’t we give a specific Target value we’re looking for when we add the event listener? Enter TargetModelEvents! We looked at most of this code already so I’ll try to streamline it… first, again, the pieces that make the model work: TargetModelEvent This is the actual Event that gets sent to your callback: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 package com.zf.events { public class TargetModelEvent { // The ID of the component the event was set on public var contextId:String;   // the model Object the event happened on public var model:Object;   // […]

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images