The resource Tag

You have seen that the LzView class has the resource attribute that can be assigned the URL to an external attribute. Using this attribute, you can assign an image or a Flash. However, its use is quite limited. The resource attribute, for example, cannot play MP3 song.

The resource tag is similar in functionality to the LzView class’s resource attribute. However, it gives you more flexibility and power. For one, when used with frames, you can associate a resource with multiple images, each image linked to a frame. Secondly, the resource tag can be used to play MP3 songs, something the LzView class cannot do.

The resource tag has two attributes, listed in Table 2.16.

Table 2.16. The resource tag’s attributes
NameUsageTypeDefaultAccessibility
nameTag onlystring final
 Description. An identifier for this resource.
srcTag onlystring final
 Description. The URL to an external file to be associated with this resource.

Listing 2.14 shows an LZX application that uses the resource tag to link an MP3 file.

Listing 2.14. Playing MP3 song
<canvas height="150">
    <simplelayout axis="x"/>
    <resource src="mySong.mp3" name="mp3"/>
    <button text="Play"
           onclick="LzAudio.playSound('mp3'),"/>
    <button text="Stop"
           onclick="LzAudio.stopSound('mp3'),"/>
</canvas>

Note that the resource tag in Listing 2.14 is linked to the mySong.mp3 file. This file in not deployed with the zip file that contains the sample applications for this book. To test the application, find an MP3 file and reassign the src attribute.

To run the application in Listing 2.14, use this URL:

http://localhost:8080/lps-4.0.x/app02/resourceTest1.lzx

Figure 2.19 shows the result for successful compilation. Click the Play button to play the MP3 song, and the Stop button to stop the song.

Figure 2.19. Playing MP3 Files


Note

See also the section “The frame Tag” for more use of the resource tag.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset