Java Reference
In-Depth Information
// 20: Should never get here
"{__DIR__}images/blank.png",
// 21-29 represents editable spaces in conflict
"{__DIR__}images/1-red.png",
"{__DIR__}images/2-red.png",
...
"{__DIR__}images/9-red.png",
// 30: Should never get here
"{__DIR__}images/blank.png",
// 31-39 represents non-editable spaces in conflict
"{__DIR__}images/1-red-bold.png",
"{__DIR__}images/2-red-bold.png",
...
"{__DIR__}images/9-red-bold.png"
];
As you may have surmised, the image files coincide with the layout of a
Space
's
number
instance variable as described in Table 13.3. For example,
imageFiles[0]
contains the URL
"{__DIR__}images/blank.png"
—a blank space—whereas
imageFiles[19]
points to
"{__DIR__}images/9-bold.png"
—an image of the
number 9 in bold, representing a non-editable space. The
imageFiles
sequence,
however, only contains strings that refer to URLs. What we actually need here is
a sequence of type
Image
to serve as an
Image
cache. This is achieved by using
imageFiles
with the following code:
// Cached copies of Number Images
var images = for(url in imageFiles) {
Image {
url: url
backgroundLoading: true
}
}
Next, each
SpaceNode
defines two instance variables, one called
spaceImage
,
which holds the current image displayed for each instance, and
number
, which
contains the value of the corresponding
Space
's
number
instance variable. Using
a combination of binding and triggers, we can achieve the effect of updating a
SpaceNode
's current image whenever its corresponding
Space
has a change in its
number
variable. This is accomplished with the following code:
protected var spaceImage:Image;
public var number:Integer = bind space.number on replace {
spaceImage = images[number];
};
Search WWH ::
Custom Search