changing substring to a variable number
by Shane Williams
on
Nov 3, 2009 at 2:26:00 am
I have thumbnail images called "image1" to "image12" and when you click on these images they take you to the frame label with the larger image in another movie clip. I am hard coding mostly.
It works fine when you click image 1 because it adds 1 everytime but I don't know how to use the substring to convert the frameVar to the thumbnail that has been chosen.
I want to use the number on image4 and change that to my number variable. I am using myString.substring(5,7)); to take out the numbers from image5 when it is clicked but can't convert that to a number to update the frameVar.
////////////////the trace works and I get the number but I don't know how to convert this from text to a number and change my frameVar to the thumbnail selected
////////////////goes to the next frame once in the photoLargeLoad_mc
function loadImageLargeNext(event:MouseEvent):void
{
//////////trace button
trace("go to this "+event.target.name+" "+frameVar+" in the Gallery section");
Re: changing substring to a variable number by Shane Williams on Nov 3, 2009 at 5:37:13 am
Thanks Gunther,
But how do I add the substring to frameVar?
function loadImageLarge(event:MouseEvent):void
{
//////////trace button
/////////////goes to the scene of the button clicked
var myString:String = (event.target.name);
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.gotoAndStop(myString);
var n:Number = myString.substring(5,7);
//frameVar(n);
trace(frameVar);
Re: changing substring to a variable number by Shane Williams on Nov 3, 2009 at 9:10:24 am
var frameVar:Number = 1;
function loadImageLarge(event:MouseEvent):void
{
//////////trace button
/////////////goes to the scene of the button clicked
var myString:String = (event.target.name);
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.gotoAndStop(myString);
var mySubstring = (myString.substring(5,7));
var myNewNumber:Number = (mySubstring);
//myNewNumber = Number(frameVar);
var frameVar:Number = (myNewNumber);
trace("this is myString "+myString);//////output///this is myString image9
trace("this is the Substring "+mySubstring);/////output///this is myString image9
trace("this is the myNewNumber "+myNewNumber);/////output///this is myNewNumber 9
trace("this is the frameVar "+frameVar);/////output///this is the frameVar 9
}
output////////////
go to this nextArrow_btn frameVar 1 in the Gallery section
but at the end it refers back to the original frameVar value of 1
Re: changing substring to a variable number by Shane Williams on Nov 6, 2009 at 8:25:37 am
Thanks for the advice, will have to check it out the XML tutorial. I wanted to sort this out as I learnt about substrings and I added a tween as well!
I got a good response from Rich Schupe at Learning Action Script 3.0 and used this to change the substring to the new Var. It needed to be an integer.
var frameVar:int = 1;
function thumbnailClick(evt:MouseEvent):void
{
var imageName:String = (evt.target.name);
frameVar = int(imageName.substring(5, imageName.length));
loadImageLarge();
trace("this is myString "+imageName);
}
function loadImageLarge():void
{
//////////trace button
/////////////goes to the scene of the button clicked
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.gotoAndStop("image"+frameVar);
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc.gotoAndStop("image"+frameVar);
fadeTween = new Tween(mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc,"alpha", None.easeNone,0,1,1,true);
trace("this is the frameVar "+frameVar);
}
////////////////goes to the next frame
function loadImageLargeNext(event:MouseEvent):void
{
//////////trace button
trace("frameVar "+frameVar+" number");
/////////////goes to image plus the new number
frameVar++;
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.gotoAndStop("image"+frameVar);
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc.gotoAndStop("image"+frameVar);
fadeTween = new Tween(mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc,"alpha", None.easeNone,0,1,1,true);
}
////////////////goes to the next frame
function loadImageLargePrevious(event:MouseEvent):void
{
//////////trace button
trace("go to this "+event.target.name+" "+frameVar+" in the Gallery section");
/////////////goes to image minus the new number
frameVar--;
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.gotoAndStop("image"+frameVar);
mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc.gotoAndStop("image"+frameVar);
fadeTween = new Tween(mediaData_mc.photosFadeUp_mc.photosData_mc.photoLargeLoad_mc.PhotoContainerLarge_mc,"alpha", None.easeNone,0,1,1,true);