1st layout - why do you loop to array.height? I don't know your array structure, but it's usually array.width. Also, when you are loading multiple images into one sprite, you need to load them to different frames. Otherwise all sprite instances will have the same image. So you create a sprite, change its frame, and then load image.
2nd layout - after you switch to another layout, "hm" sprite is no longer available. Even if you set it as Global, this layout doesn't know which sprite was tapped. So before changing layouts you need to save hm.Qname in a global variable and then on start of the second layout use that variable to request a file with AJAX.
.
You need to start using debugging tools. Run the game in Debug Mode, you will be able to see the array content, how many hm sprites are created, instance variables for these sprites etc.
Also, use "Browser Log" to output debug messages. For example, after "AJAX request hm.Qname" add another action:
Browser Log "Requesting filename: " & hm.Qname
Then run the project, press F12, open Console and see what happens.