f00d
f00d

Reputation: 581

AS3 issues with an Array, anything past 9 in the array won't respond to the tweenlite animations

So I've run into a problem with my code to where any thumbnail I click after number9 will play the corresponding video however, the animation to return to its x value and to alpha dim the thumbnail stop working.

I believe it has to do with my charSet of 5 characters. But i'm not sure how to get it to follow anymore characters. So I'm essentially stuck. I need to support 15 videos in an array, but I can't go past video 10, because the tweenlite won't tween or dimming of the image don't happen.

var currentNum:Number = 1;
var videoNum:Array = new Array();
videoNum[1] = "vid1.flv"
videoNum[2] = "vid2.flv"
videoNum[3] = "vid3.flv"
videoNum[4] = "vid4.flv"
videoNum[5] = "vid5.flv"
videoNum[6] = "vid6.flv"
videoNum[7] = "vid7.flv"
videoNum[8] = "vid8.flv"
videoNum[9] = "vid9.flv"
videoNum[10] = "vid10.flv"
videoNum[11] = "vid11.flv"
videoNum[12] = "vid12.flv"
videoNum[13] = "vid13.flv"
videoNum[14] = "vid14.flv"
videoNum[15] = "vid15.flv"



var player:videoPlayer = new videoPlayer();
player.videoURL = videoNum[currentNum];

addChild(player);

for (var i = 1; i<16; i++){
   content_mc["thumb"+i].addEventListener(MouseEvent.CLICK, thumbClick);
   content_mc["thumb"+i].buttonMode = true;
   content_mc["thumb"+i].playBtn.mouseEnabled = false;
   content_mc["thumb"+i].alpha = .5;
}
content_mc.thumb1.alpha = 1;
content_mc.thumb1.x = -111.75;
content_mc.thumb1.playBtn.alpha = 0;

function thumbClick(event:MouseEvent):void{
var currentVideo = "thumb" + currentNum
TweenLite.to(content_mc[currentVideo], 1, {x:-100, alpha:.5,  ease:Expo.easeOut})
TweenLite.to(content_mc[currentVideo].playBtn, 1, {alpha:.5,  ease:Expo.easeOut})

player.ns.seek(0);
player.ns.togglePause();
var clicked = event.target;

TweenLite.to(clicked, 1, {x:-111.75, alpha:1,  ease:Expo.easeOut})
TweenLite.to(clicked.playBtn, 1, {alpha:0,  ease:Expo.easeOut})

var clickedName = event.target.name;

currentNum = clickedName.charAt(5);

switch (clickedName){

    case "thumb1":
    TweenLite.to(content_mc.currentIcon, 1, {y:-689.9,  ease:Expo.easeOut})
    break;
    case "thumb2":
    TweenLite.to(content_mc.currentIcon, 1, {y:-589.9,  ease:Expo.easeOut})
    break;
    case "thumb3":
    TweenLite.to(content_mc.currentIcon, 1, {y:-499.3,  ease:Expo.easeOut})
    break;
    case "thumb4":
    TweenLite.to(content_mc.currentIcon, 1, {y:-405.8,  ease:Expo.easeOut})
    break;
    case "thumb5":
    TweenLite.to(content_mc.currentIcon, 1, {y:-311,  ease:Expo.easeOut})
    break;
    case "thumb6":
    TweenLite.to(content_mc.currentIcon, 1, {y:-220.4,  ease:Expo.easeOut})
    break;
    case "thumb7":
    TweenLite.to(content_mc.currentIcon, 1, {y:-125.6,  ease:Expo.easeOut})
    break;
    case "thumb8":
    TweenLite.to(content_mc.currentIcon, 1, {y:-30.8,  ease:Expo.easeOut})
    break;
    case "thumb9":
    TweenLite.to(content_mc.currentIcon, 1, {y:59.8,  ease:Expo.easeOut})
    break;
    case "thumb10":
    TweenLite.to(content_mc.currentIcon, 1, {y:151,  ease:Expo.easeOut})
    break;
    case "thumb11":
    TweenLite.to(content_mc.currentIcon, 1, {y:248.15,  ease:Expo.easeOut})
    break;
    case "thumb12":
    TweenLite.to(content_mc.currentIcon, 1, {y:338.75,  ease:Expo.easeOut})
    break;
    case "thumb13":
    TweenLite.to(content_mc.currentIcon, 1, {y:437.75,  ease:Expo.easeOut})
    break;
    case "thumb14":
    TweenLite.to(content_mc.currentIcon, 1, {y:532.55,  ease:Expo.easeOut})
    break;
    case "thumb15":
    TweenLite.to(content_mc.currentIcon, 1, {y:623.15,  ease:Expo.easeOut})

}

player.videoURL = videoNum[currentNum];
player.started = false;
player.TOGGLEPAUSE();
player.Reset();
}

Upvotes: 0

Views: 30

Answers (2)

helloflash
helloflash

Reputation: 2470

You should use susbtring method, which returns a string consisting of the character specified by startIndex and all characters up to endIndex. If the parameter endIndex is omitted, String.length is used.

currentNum = clickedName.substring(5);

You can also use substr method, which returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len. If len is not specified, the substring includes all the characters from startIndex to the end of the string.

currentNum = clickedName.substr(5);

If you want to learn more about String properties and methods.

Upvotes: 0

Cadin
Cadin

Reputation: 4649

This is your problem right here:
currentNum = clickedName.charAt(5);

You're only grabbing a single character to get the index of the item clicked. So if you click item 10, currentNum will be set to 1, not 10.

A quick fix would be to use substr instead of charAt. It will let you grab all the characters starting at a given index up to the end of the string:
currentNum = clickedName.substr(5);

Although...
You might be better off storing all those items in an array and referring to them by index (instead of trying to construct and deconstruct the item names every time you want to refer to them).

Upvotes: 1

Related Questions