Adding & Removing images using ActionScript

You can insert images into the gridNavigation through ActionScript (besides inserting them through the Component Inspector or through XML). This tutorial shows you how to insert additional photos through ActionScript using the addItem() method and the properties for Actionscript 2 or Actionscript 3 respectively.

 

1. If you have not already done so you should first complete the Getting Started section and then open the file that you created in Flash.


2. Select the gridNavigation component that's on the stage and open the properties panel. Assign an instance name to the component. For the purpose of this tutorial, call it gridNavigation




3. Deselect the component by clicking on the keyframe on the timeline and press F9 to open the Actions panel

 

Enter the code below:

gridNavigation.setThumbnailDimension(100, 50);
gridNavigation.setImageDimension(300, 200);


gridNavigation.addItem("data/images/thm/1.jpg", "data/images/img/1.jpg");
gridNavigation.addItem("data/images/thm/2.jpg", "data/images/img/2.jpg");
gridNavigation.loadItems();

This script adds 2 image. The images are added to the gridNavigation component on the third and fourth lines.


4. Press Ctrl+Enter (win) or Cmnd+Enter (mac) to test your file.