PDA

View Full Version : Help Needed: Stopping last element in array incriment



wyclef
March 30th, 2004, 12:00 PM
Hello,


I've got code that takes text from an array and places it into a textbox. The first spot in the array is supposed to be null to correspond with the first section of the swf which shouldn't have any text. But after navigating through the different array elements the movie gets confused and doesn't recognize that the first slot should be empty and shifts things out of order.

What seems to be happening is when you are clicking the buttons to go to the sections there is a variable that is either incrimented or decrimented so that it can be used as the index for the array. It would seem that this variable is not being kept track of properly, as when you are at the end of the Array and there is no more sections you can still press the button that would incriment this variable and thus move to an element in the array that isn't there (being array.length + 1 or -1 depending). so what is needed is some sort of condition that checks to see if this variable is infact at the last element in the array and if so not to incriment itself.

Here is the array code. This code is part of a loaded external movie.


portfolioSection([" ", "section 02", "section 03", "section 04"]);


And this code is in the main movie that talks to the array in the external file.


var aSectionTxt;
var iSectionIndex = 0;

_global.portfolioSection = function (a) {
targetX = 527;
path = _root.sectionMC_03.folioClip
maxWidth = path.section_mc._width-529;
velocity = 4;
aSectionTxt = a.concat();

path.section_mc.initEnterFrame();
path.forward_btn.onRelease = function() {
if (targetX>-(maxWidth-370)) {
targetX -= 370;
path.section_mc.initEnterFrame(1);
}
};

path.back_btn.onRelease = function() {
if (targetX<527) {
targetX += 370;
path.section_mc.initEnterFrame(-1);
}
};
};
MovieClip.prototype.initEnterFrame = function(dir) {
path.section_txt.text = "";
if (mcMovieToRemove != null) {
removeMovieClip(mcMovieToRemove);
}
this.onEnterFrame = function() {
trace("Running Enter Frame");
this._x += (targetX-this._x)/velocity;
if (this._x&lt<img src="images/smilies/frustrated.gif" border="0" alt="">targetX+1) && this._x&gt<img src="images/smilies/frustrated.gif" border="0" alt="">targetX-1)) {
trace("Stopping Enter Frame");
this._x = targetX;
setSectionText(dir);
delete this.onEnterFrame;
}
};
};
_global.setSectionText = function (dir) {
if (dir != undefined) {
iSectionIndex += dir;
}
if (typeof (aSectionTxt[iSectionIndex]) == "string") {
path.section_txt.text = aSectionTxt[iSectionIndex];
} else {
mcMovieToRemove = path.attachMovie(aSectionTxt[iSectionIndex].linkage, "mcSectionMovie", 10);
mcMovieToRemove._x = aSectionTxt[iSectionIndex].x;
mcMovieToRemove._y = aSectionTxt[iSectionIndex].y;
}
};


I've been struggling with this for some time now, and had previously posted a thread about this earlier on but it's since been deleted because there have been no responses and I wanted to try to present the problem a little clearer. Your help would be greatly appreciated. Thanks.

Lost
March 30th, 2004, 12:12 PM
That looks like a lot of code and my eyes hurt, how big is your fla can you upload that?

wyclef
March 30th, 2004, 12:29 PM
It's too big to upload. Could I email it to you?

Lost
March 30th, 2004, 12:31 PM
yup admin@internet-plans.com

Lost
March 30th, 2004, 01:42 PM
alright got your email, give me a few

Lost
March 30th, 2004, 03:31 PM
well, i've worked on it for about 3 hours now really didnt get anywhere, most of your files are locked (which I can unlock) and it just looks all confusing to me (all the MC's etc) i understand the code and everything but just to much, I would have to make the dang thing to understand it.

sorry couldnt help, just to much! :)
maybe if it was easier to understand the layout and the concept I would nail it for sure!

lost

p.s. your right, i was more lost

wyclef
April 2nd, 2004, 03:28 PM
Can we hook up on AIM sometime?

wyclef
July 19th, 2004, 01:01 PM
Can someone help me incorporate this check to see if we are at end of array in a way that would help out my problem?



if(dir == your_array.length-1){
// at the last element,do something intresting
}else{
// not at las element so do something intresting
}

wyclef
July 20th, 2004, 12:00 PM
Check this out. I zipped up some files that simulate my problem.

clickme.swf = main.fla
abs.swf = external.fla

To first see the problem, open "clickme.swf"...the click "Click Me"...then wait until movement stops then click "001 - CLICK ME". This will open up the external swf in the bottom left. Now click forward once, see the dynamic text "Section 01" then click back once. No text. The first section is the blank part in the array. Now go crazy and start clicking forward a lot then back then forward then back all over and then finally click back to the beginning. If you do this enough, you will notice that the array is all mixed up and text is displayed in the first section.

I cannot figure this out. The important code can be found in main.fla within the MC in the "our work" layer. The associated array can be found in external.fla. If anyone can help me figure out what is causing this I would be very happy because everything else works great. Thanks.

wyclef
February 7th, 2005, 11:42 AM
Anyone have any ideas on this? I know it's an old thread but i'm still having the same problem.

virusescu
February 7th, 2005, 03:38 PM
your_array.length returns a number -1 is another number :)... you need to use that number to addres an item in your array


if(dir == your.array[your_array.length-1]){
// at the last element,do something intresting
}else{
// not at las element so do something intresting
}

wyclef
February 7th, 2005, 05:55 PM
i don't understand how this fits into the main code?

virusescu
February 8th, 2005, 03:16 AM
Sorry.. I misunderstood your problem. I didn't had flash till now.
Now I finally took a look at your files buutttt.. it's way out of my reach.

I couldn't find any onPress or onMouseDown event. Where are the actions for your back/forward buttons? Where do you set the dir value? I found the setSectionText function definition.. and where it's called... but you call it something like setSectionText(dir) and I couldn't find the dir. Surely the problem is there nearby.

Not to mention that I put a trace inside the setSectionText function and it didn't showed up, although the function seem to be working.. setting the text (even if not the way you wanted)...

Have you draw any conlcusions so far?
Sorry I couldn't be of more help. :|

2nd day
February 8th, 2005, 07:12 AM
i couldn't find the back and forward actions neither... i think your problem will be there somewhere...

wyclef
February 8th, 2005, 11:15 AM
path.forward_btn.onRelease = function() {
if (targetX>-(maxWidth-370)) {
targetX -= 370;
path.section_mc.initEnterFrame(1);
}
};

path.back_btn.onRelease = function() {
if (targetX<527) {
targetX += 370;
path.section_mc.initEnterFrame(-1);
}
};


the forward_btn and back_btn are located in the external file so they just have instance names. This is the code associated with them. Is that what u were asking?

2nd day
February 8th, 2005, 11:39 AM
did you include that external file in the .zip?

wyclef
February 8th, 2005, 12:28 PM
yea. external.fla

wyclef
February 8th, 2005, 04:47 PM
figure anything out? i'm completely stuck.

2nd day
February 8th, 2005, 05:24 PM
well i found the code... it took some time... now i can have i look. I just want to say you have a strange way of putting it all together... (it's just an opinion... ;))

2nd day
February 8th, 2005, 06:01 PM
i'm sorry man... this is to complicated for me... :puzzled:

wyclef
February 8th, 2005, 06:58 PM
aye carumba! anyone else up for the challenge? nobody seems to be able to figure out the problem...

wyclef
February 9th, 2005, 01:08 PM
i added a trace of iSectionIndex inside the code and if u test movie u can clearly see the problem in the trace. When u click forward it counts up 1,2,3,4 like it's supposed to but when u get to the last slide if u click 1 more and nothing is there, and then go back it will go to 5 instead of back down to 3 and the everything gets thrown off.



path.forward_btn.onRelease = function() {
if (targetX>-(maxWidth-370)) {
trace(iSectionIndex);
targetX -= 370;
var dir = 1;
if (iSectionIndex+dir>=0 && iSectionIndex+dir<=aSectionTxt.length) iSectionIndex += dir; // iSectionIndex must be set here -- not at the end of the enterframe func.
path.section_mc.initEnterFrame();
}
};

path.back_btn.onRelease = function() {
if (targetX<527) {
trace(iSectionIndex);
targetX += 370;
var dir = -1;
if (iSectionIndex+dir>=0 && iSectionIndex+dir<=aSectionTxt.length) iSectionIndex += dir; // iSectionIndex must be set here -- not at the end of the enterframe func.
path.section_mc.initEnterFrame();
}
};

wyclef
February 10th, 2005, 01:04 PM
anyone?

wyclef
February 15th, 2005, 11:10 AM
Now I tried changing part of the code to this...but it didn't work. Anyone have any insight?



_global.portfolioSection = function (a) {
targetX = 527;
path = _root.sectionMC_03.folioClip
maxWidth = path.section_mc._width-529;
velocity = 4;
aSectionTxt = a.concat();

path.section_mc.initEnterFrame();
path.forward_btn.onRelease = function() {
if(dir == portfolioSection.length-1){
// Do nothing end of array
}else{

if (targetX>-(maxWidth-370)) {
targetX -= 370;
path.section_mc.initEnterFrame(1);
}
}
};

path.back_btn.onRelease = function() {
if(dir == 0){
//Do nothing begining of array
}else{
if (targetX<527) {
targetX += 370;
path.section_mc.initEnterFrame(-1);
}
};
}
};

wyclef
February 21st, 2005, 02:07 PM
anyone?

wyclef
March 17th, 2005, 03:26 PM
???

wyclef
April 1st, 2005, 02:07 PM
Anyone have any ideas about this?

wyclef
April 19th, 2005, 01:04 PM
Anyone have any ideas about this?