Flash Basics tutorial

 

Popup window tutorial 2.4.12

 

Making a gallery window:

A) first test button and counting

1) create a button with instance name: mytestButton_btn

2) create a dynamic text field with instance name messageBox

3) following code goes to frame 1

  
var buttonCount:uint = 0;

mytestButton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
		buttonCount = buttonCount + 1;
		messageBox.text = "you clicked button " + buttonCount + " times ";
}

B) test filenames:

4) change the code like this:

var buttonCount:uint = 0;
var imageFileNames:Array = ["rantakukka.jpg","0A_0490.jpg","IMG_0019.jpg"];

mytestButton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
		
		messageBox.text = "you are selecting image name " +  imageFileNames[buttonCount] ;
       buttonCount = buttonCount + 1;
		
}

C) roll the indexes to zero when index bigger than the size of array:

5) change the code like this:

  var buttonCount:uint = 0;
var imageFileNames:Array = ["rantakukka.jpg","0A_0490.jpg","IMG_0019.jpg"];
mytestButton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

  function fl_MouseClickHandler_2(event:MouseEvent):void
{
		
		messageBox.text = "index " + buttonCount +" and image name " +  imageFileNames[buttonCount] ;
		buttonCount = buttonCount + 1;
		if (buttonCount > imageFileNames.length-1)
		buttonCount = 0;
}

D) load images:

6) create an empty movieclip as an image placeholder and place it in the stage with instance name:placeHolder_mc

6a) Insert > new symbol

6b) place new empty movieclip from library to stage, give instance name:placeHolder_mc

7) place file called ImageLoad4.as (from S:\flash basics 2012\lesson05) into same folder as your flash project

8) change the code like this:

 

var buttonCount:uint = 0;
var imageFileNames:Array = ["rantakukka.jpg","0A_0490.jpg","IMG_0019.jpg"];

mytestButton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

var imageLoad:ImageLoad4 = new ImageLoad4();
placeHolder_mc.addChild(imageLoad)


function fl_MouseClickHandler_2(event:MouseEvent):void
{
		imageLoad.loadImage(imageFileNames[buttonCount]);
		messageBox.text = "index " + buttonCount +" and image name " +  imageFileNames[buttonCount] ;
		buttonCount = buttonCount + 1;
		if (buttonCount > imageFileNames.length-1)
		buttonCount = 0;
}


9) left button code (instance name for left button: left_button)


var index:int = 0; // uint: unsigned integer
var imageFileNames:Array = ["rantakukka.jpg","0A_0490.jpg","IMG_0019.jpg"];


var imageLoad:ImageLoad4 = new ImageLoad4();
placeHolder_mc.addChild(imageLoad)

mytestButton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
		index = index + 1;
		if (index > imageFileNames.length-1)
		index = 0;
		imageLoad.loadImage(imageFileNames[index]);
		messageBox.text = "index " + index +" and image name " +  imageFileNames[index] ;
		
}

left_button.addEventListener(MouseEvent.CLICK, onLeftButtonClick);
function onLeftButtonClick(event:MouseEvent):void
{		
		index = index - 1;
		if (index < 0 )
		index = imageFileNames.length-1;
		imageLoad.loadImage(imageFileNames[index]);
		messageBox.text = "index " + index +" and image name " +  imageFileNames[index] ;

}