Java Reference
In-Depth Information
4. Then, we create another sequence instance, images , into which we are going to load
instances of Image class representing the PNG files:
// load each image and add to sequence
var images :Image[];
for(i ( letter in alphabet ){
insert Image {
url: "{__DIR__}images/{letter}.png"
backgroundLoading: false
width:imgW height:imgH
} into images ;
}
5. Once the images are loaded, the code declares an instance of ImageView that will
be used to display the image on the screen:
var imgView = ImageView {
x: (w - imgW)/2 y: (h - imgH)/2
preserveRatio: true
image: null
}
6. The last code segment requests input focus for the ImageView object. Then,
we define a keyboard event-handler function to display the letter when a letter
key is pressed:
imgView. requestFocus ();
imgView.onKeyPressed = function (e:KeyEvent) {
imgView.image = {
var img:Image = imgView.image;
for(i in images){
if(i.url.contains("{e.text}.png")) {
img = i;
break;
}
}
img
}
}
 
Search WWH ::




Custom Search