Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




How Do I Get The *loadSound* AS Code To Loop?



Currently I have this... But unsure of how to get the song to loop,
Ive tried music.start(0,99) but it then doesnt even play the song...


on (release) {
music = new Sound();
music.loadSound("http://home.nesbeonline.com/hattrick/test.mp3", true);
}



FlashKit > Flash Help > Flash General Help
Posted on: 02-26-2004, 11:02 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

To Loop A Loadsound?
Hi
How do I loop a loadSound ?
i have tried various approaches and cant seem to get it!
my script is like this -

var my_sound:Sound = new Sound();
my_sound,loadSound(http://mywebsite.com/intro.mp3,true);


any help on this would be great thanks!

Mp3 Loop Via LoadSound() - Gap?
Hi there

I have searched for this problem but all the threads did not really resolve the problem.

The problem as we all know mp3 loops can have a gap at the end. Lots of the threads suggested using .wav instead and let flash convert to mp3 then use attachSound

BUT what can you do if you are and having to use loadSound -

Also currently I am looping by

onSoundCompleate - start sound is this the best approach

Many thanks

shef

Loadsound And Loop Problem
Hey,

I want to load a sound external and loop it, but It wont loop!


ActionScript Code:
muziek = new Sound ();
muziek.loadSound("muziek/1.mp3",true);
muziek.start(0,99);

What do I wrong?
It just play one time.

LoadSound Loop Problem
Hi,

I have run into a major problem.

I get a sound into my swf using the new loadSound method in MX. It works perfectly fine like this:


Code:
whatSound = new Sound();
whatSound.loadSound("test.mp3",false);
The sound plays perfectly.

The problem is actually not in Flash. The problem is that when encoding my wav file into the mp3 format, it puts in a little silence in the beginning and in the end of the sound. (I discovered that in my cool edit)

This makes it impossible to make a loop that doesn't have gaps.

If just I could import a wav file, then my worries would be over

I have been looking all over the web for encoders that doesn't include the goddamn silence.

Any suggestions to how I can solve this problem ?

There must be some hardcore encoding/sound gurus out there doing loops in Flash.

Looking forward to your help.

Thanks
Tony Hanna
Impulsive

Loadsound Loop Question
Hi,

I am using this code which works but doesnt loop:

myMusic = new Sound();
myMusic.loadSound("music.mp3", true);

How do I make this loop? I have seen:

myMusic = new Sound();
myMusic.loadSound("muisc.mp3");
myMusic.start(0,9999);

Corrrect?

Pausing Execution Of Code In A For Loop Between Each Loop. Howto?
I have a for loop which runs x amount of times and between each loop i'd like to implement a small pause of execution of the code. How would i do that? Can something like that only be done using a timer? If so how would i go about doing that and what things should i import? (Trying to do this in a class) ...

Pausing Execution Of Code In A For Loop Between Each Loop. Howto?
I have a for loop which runs x amount of times and between each loop i'd like to implement a small pause of execution of the code. How would i do that? Can something like that only be done using a timer? If so how would i go about doing that and what things should i import? (Trying to do this in a class)
Though i'm wondering if there's an easier way than timers to be able to do something like that, like C's sleep() function for example.

First Loop 1 Sec, Next Loop 10 Sec, Have Code
I have this code in the last frame

Code:
stop();
var loop = true;
var timer = setInterval(makeLoop, 10000);
function makeLoop()
{
if(loop)
{
loop = false;
clearInterval(timer);
Play();
}
}
How can i put something in the first frame, so that the first loop take 1 sec, and then the code above will kick in instead of the code in the first frame?
btw, im a newbie.

EDIT:
i know that i can create a varible in the first frame like:

Code:
If (xx) {
} else {
make first loop 1 sec
xx = true;
}

Plz Help To Code A Loop :(
Dear all,

Below is my code for my family picture viewer using external JPEGS

Now I want to add a button for AUTOPLAY... that is, when this button is clicked, the movie keeps going to the next jpeg automatically .
and a companion stop button..

can someone help me with it ?


Thanks
------------------------------------------------------------------
fscommand("fullscreen", "true");
fscommand("showmenu", "false");
fscommand("allowscale", "true");
slides_xml = new XML();
slides_xml.onLoad = startSlideShow;
slides_xml.load("sds.xml");
slides_xml.ignoreWhite = true;
targetClip._alpha = 0;
//
// Show the first slide and intialize variables
function startSlideShow(success) {
if (success == true) {
rootNode = slides_xml.firstChild;
totalSlides = rootNode.childNodes.length;
firstSlideNode = rootNode.firstChild;
currentSlideNode = firstSlideNode;
currentIndex = 1;
updateSlide(firstSlideNode);
}
}
//
// Updates the current slide with new image and text
function updateSlide(newSlideNode) {
imagePath = newSlideNode.attributes.jpegURL;
// added this to create a temp mc that can be removed
// _root.createEmptyMovieClip("temp_mc", -500);
// added this to get the alpha fading to work properly
// _root.temp_mc.onEnterFrame = function()
onEnterFrame = function () {
if (targetClip._alpha>10 && fadeOut) {
targetClip._alpha -= 10;
}
if (targetClip._alpha<10) {
targetClip.square_clip.loadMovie(imagePath);
targetClip2.square_clip.loadMovie(imagePath);
fadeOut = false;
fadeIn = true;
}
if (targetClip._alpha<100 && fadeIn && !fadeOut) {
targetClip._alpha += 10;
}
else {fadeIn = false;}
if (input>30)
{
input = 30;
}
slideText = newSlideNode.firstChild.nodeValue;
styleId = newSlideNode.attributes.ID;};
}
//
//
// Event handler for 'Next slide' button
next_btn.onRelease = function() {
nextSlideNode = currentSlideNode.nextSibling;
if (nextSlideNode == null) {
break;
} else {
updateSlide(nextSlideNode);
currentSlideNode = nextSlideNode;
if (currentIndex<30 && !fadeIn && !fadeOut) {
fadeOut = true;
currentIndex++;
input = currentIndex;
}
}
};
//
// Event handler for 'Previous slide' button
back_btn.onRelease = function() {
previousSlideNode = currentSlideNode.previousSibling;
if (previousSlideNode == null) {
break;
} else {
currentSlideNode = previousSlideNode;
updateSlide(previousSlideNode);
if (currentIndex>1 && !fadeIn && !fadeOut) {
fadeOut = true;
currentIndex--;
input = currentIndex;
}
}
};

Code Loop Help
Hi everyone, I posted this in a couple of other forums but haven't gotten a response yet, I am somewhat anxious to solve this problem as my presentation is all but done aside from this. I've been stuck on it for 3 days now so that doesn't help either .

I'm creating a presentation where halfway through, it cuts to an overhead view of raindrops hitting the ground. I found a nice .fla here on flashkit that had the code module I needed. The only problem is that the code executes continuously throughout the presentation once the timeline hits the frame. This continues even after the movie finishes and loops back to the beginning.

I've tried numerous removeclip varitions, unload variations and anything else I could think of. Even tried altering the code what bit I could. Can anyone tell me why this code loops endlessly? Here's the default code unaltered. "drop" and "drop1" are the movie clips that the computations use to display the drops.

count += 1;
if (count%2) {
_root.attachMovie("drop", "d"+count, count);
} else {
_root.attachMovie("drop1", "d"+count, count);
}
eval("d"+count)._x = Math.floor(Math.random()*150)+50;
eval("d"+count)._y = Math.floor(Math.random()*150)+50;
eval("d"+count)._rotation = Math.floor(Math.random()*360);
eval("d"+count)._alpha = Math.floor(Math.random()*45)+45;
if (count>12) {
remNum = count-12;
removeMovieClip(eval("d"+remNum));
}



If you need the .fla to better help me, it's here.
http://www.flashkit.com/downloads/mo.../5529/Rain.zip

Loop Code
Code:
myCBoxListener = new Object();
myCBoxListener.change = function ( eventObj )
{
var eventSource = eventObj.target;

var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
var theSelectedItemValue = theSelectedItem.data;


if (theSelectedItemValue == 1)
{



Westernmc = new Color(_root.mapcontainer.mapmc.Westernmc);
Westernmc.setRGB(0x00CC00);
NorthWesternmc = new Color(_root.mapcontainer.mapmc.NorthWesternmc);
NorthWesternmc.setRGB(0x00CC00);
glenelgmc = new Color(_root.mapcontainer.mapmc.Westernmc1.glenelgmc);
glenelgmc.setRGB(0x00CC00);
moynemc = new Color(_root.mapcontainer.mapmc.Westernmc1.moynemc);
moynemc.setRGB(0x00CC00);

}

else if (theSelectedItemValue == 2)
{

Westernmc = new Color(_root.mapcontainer.mapmc.Westernmc);
Westernmc.setRGB(0xC7C78D);
NorthWesternmc = new Color(_root.mapcontainer.mapmc.NorthWesternmc);
NorthWesternmc.setRGB(0xC7C78D);
glenelgmc = new Color(_root.mapcontainer.mapmc.Westernmc1.glenelgmc);
glenelgmc.setRGB(0xC7C78D);
}
}

cbmap.addEventListener ("change", myCBoxListener);


i have an issue that when i gotoandplay a different frame the above code does not have any effect and my images return to the default color

i was thinking i need to loop this so that the desiginated mc knows which
selection of the combo box has been selected

any ideas i can upload fla if needed

[F8] For Loop Code Help
I'm using the Array with the For Loop below and I'm having a problem with this line:

this["logo" + index].gotoAndPlay("fadein");

I have 8 buttons all named btn1 - btn8 and I have 8 logos named logo1 - logo8.

I'm trying to have each corresponding logo fade in with each button, but I can't figure out how to reference the names logo1 - logo8. The line mentioned above is the line in my script that doesn't seem to be working.

Help?

code:

// Btns URL Array

var urlAry = new Array("#","#","#","#","#","#","#","#");

// Btn onRollOver For Loop

for(i=1; i<=urlAry.length; i++) {
this["btn" + i].index = i;
this["btn" + i].onRollOver = function() {
this["logo" + index].gotoAndPlay("fadein");
}
}

Help How Do I Add A Loop To This Code
I know there must be an easier way to write this code using loops/arrays, but I can seem to get it working with AS3. I have been writing in AS3 for under 3 days, I just made the switch from AS2.0. Can someone help me! I would consider paying someone to explain it to me over the phone!

here is my code:


Code:
// variables
var popInfo:popMc;


// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("data/cities.xml"));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
//trace(xml.city[0].@weburl.toString());
var url:URLRequest = new URLRequest(xml.city[0].@weburl.toString());

}
);

// event listeners
stage.addEventListener(MouseEvent.CLICK, onClickStageRemove);

carBtn0.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn0.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn0.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);

carBtn1.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn1.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn1.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);

carBtn2.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn2.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn2.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);

carBtn3.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn3.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn3.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);

carBtn0.buttonMode = true;
carBtn1.buttonMode = true;
carBtn2.buttonMode = true;
carBtn3.buttonMode = true;


// functions
function onCarHover(event:MouseEvent):void
{
if(event.target == carBtn0)
{
carBtn0.gotoAndPlay(10);
}
else if(event.target == carBtn1)
{
carBtn1.gotoAndPlay(10);
}
else if(event.target == carBtn2)
{
carBtn2.gotoAndPlay(10);
}
else if(event.target == carBtn3)
{
carBtn3.gotoAndPlay(10);
}

}

function onCarOut(event:MouseEvent):void
{
if(event.target == carBtn0)
{
carBtn0.gotoAndPlay(9);
}
else if(event.target == carBtn1)
{
carBtn1.gotoAndPlay(9);
}
else if(event.target == carBtn2)
{
carBtn2.gotoAndPlay(9);
}
else if(event.target == carBtn3)
{
carBtn3.gotoAndPlay(9);
}
}


function onClickLoadData(event:MouseEvent):void
{

if(event.target == carBtn0)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[0].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[0].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[0].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[0].@name.toString();
}
else if(event.target == carBtn1)
{
popInfo = new popMc();
popInfo.x = 130;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[1].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[1].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[1].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[1].@name.toString();
}
else if(event.target == carBtn2)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[2].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[2].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[2].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[2].@name.toString();
}
else if(event.target == carBtn3)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[3].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[3].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[3].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[3].@name.toString();
}

}


function onClickRemove(event:MouseEvent):void
{
removeChild(popInfo);
}

function onClickStageRemove(event:MouseEvent):void
{
if(event.eventPhase == EventPhase.AT_TARGET) {
removeChild(popInfo);
}
}

function onClickNYOP(event:MouseEvent):void
{
//navigateToURL(url, "_blank");
// navigateToURL(urlNY, "_blank"); //trying to get this variable to work
ExternalInterface.call("selectNY");

}

// set button mode here

Loop Code In AS3
Hi there, new to Actionscript in general, I have this snippet of code that I want to loop over and over forever:

quote:if(controlID.text == "2"){
trace("worked");
}else{
trace("didn't work");
}

Is it possible to create a loop that will do this?

For Loop Code Help
This comes up often for me when coding. How do you target the previous MC in a for loop. Basically I am attaching MC's to the stage that are 90 Pixels apart from the top and bottom. I want to check the _x location of the previous MC and move in 90 pixels. Use an If statement so the _x location is not beyond 260 and if it is it moves _y 90 pixels and resets the _x. Is this the best way to do it.




Code:
function yelGallery () {
for (var i = 10; i < 20; i++) {
var galleryMC:MovieClip = (_root.attachMovie ("galleryMC", "galleryMC" + i, i));
galleryMC10._x = 70;
trace (this.galleryMC) -1))
if (this.galleryMC._x > 260) {
this.galleryMC._x = 70;
this.galleryMC._y = /*how do I target the previous MC*/this.galleryMC._y + 90;
} else {
this.galleryMC._x = this.galleryMC._x + 90;
}
_root.myMCL.loadClip ("Galleries/forSale/tn_forSale/tn_painting" + curPaintingNum + ".jpg", _root.galleryMC);
}
}

How To I Run A Code Only ONCE When In A Loop?
I don't know how many times I have come a crossed this and I'm sure there is a simple solution to it but it's just not coming to me. The most simple way I can think of right now uses a variable. If I could do this with out a variable, it would be amazing. Here is how I do it:

Code:
stage.addEventListener(Event.ENTER_FRAME, message);

var messageDone:Boolean = false;
function message(event:Event):void
{
... other code ...

if (!messageDone)
{
trace("This message is only played once instead of once every frame");
messageDone = true;
}
}
Also I was wondering if there is an eventHandler that triggers, for example, when the var messageDone == true ? Please, any advice would be much appreciated.

Code To Loop An Mp3?
I want my mp3 to loop. Does anyone know how to do this

Help With My Code(array Loop Nav)
hi,
looking for a little insight on how to have my navaigation buttons stay on when the root is on that frame label.
six buttons turned into six _mc on/off frame inside nav_mc on main timeline

Do I need to flag the release of the button to
the function or something? thanks

flagOn = true; ??

///nav function

function jump(label) {
_root.gotoAndPlay(label);
_root.bio.gotoAndStop("off"); //ignore
}


/// switch this is the function on the main timeline 1 frame

function turnOff(leaveOn) {
// trace(leaveOn);
var menu = ["yellow", "green", "blue", "purple", "red", "orange"];
for (var i = 0; i<menu.length; i++) {
if (_root.nav.menu[i] != leaveOn) {
leaveOn.gotoAndStop("off");
} else {
_root.nav.menu[i].gotoAndStop("on");
// if(_root.nav.menu[i] != leaveOn)
}
// trace(menu[i]);
}
}


///this is the code on each of the buttons inside the nav_mc on the main timeline

on (release) {
_root.turnOff(this); ///switch call
_root.jump("about"); /// nav call
}

///path _root.nav.button_mc.button

Make Code Loop
Is there a way to make actionscript code repeat itself in Flash 5?

Basically, I have a movieclip that I want to run some code, and then loop round and run it again, indefinatly. What is the trick?

----

Back in the old days of Basic you could do something like this:

10 print "hi"
20 goto 10

Is there a similar process to 'goto' in Flash 5 actionscript?

Timed Code Loop
Could someone tell me how i make a code loop that performs itself on timed intervals?

Or (even better) could you tell me how i can get a code to recognize when a external variable has been loaded into flash and then to perform a statement block?

Any help on these issues would be much appreciated thankyou!

Loop Messes Up Code...
Code:
i = 0;
while (i<3) {
i++;
_root.emptyMC.attachMovie("ob", "ob"+i, d++);
_root.emptyMC["ob"+i]._x = 150+i+i;
_root.emptyMC["ob"+i]._y = 150+i+i;
_root.emptyMC["ob"+i].onPress = function() {
startDrag(this);
};
_root.emptyMC["ob"+i].onRelease = function() {
if (_root.emptyMC["ob"+i]._y<mapH*16 && _root.emptyMC["ob"+i]._x<mapW*16) {
stopDrag();
objectX = _root.emptyMC["ob"+i]._x;
objectX -= objectX%16;
_root.emptyMC["ob"+i]._x = objectX;
}
};
}
problem is weather i drag ob1, ob2, or ob3 ob1 is the only one that gets the
objectX = _root.emptyMC["ob"+i]._x;
objectX -= objectX%16;
_root.emptyMC["ob"+i]._x = objectX;
actions...
Any iades?
Thank you for your time
~Gabor

Loop? -- Does All Other Code Stop?
when the loop is being called, say in the main timeline... do all other areas of code stop until the loop has finished or do they carry on??

also when a loop is hit, does it loop... then continue when its finished, or does it start the 1st loop get to the end of the loop then continue the rest of the code and finish the loop at the same time?

[MX] Array And For Loop Code
Hello,

Is there any reason why this code wouldn't work:


ActionScript Code:
stop();var mediaAry = new Array("audio","downloads","photogallery","video");for (i=1; i<=mediaAry.length; i++) {    this["btn" + i].index = i;    this["btn" + i].onRelease = function() {        gotoAndStop("blank");        btnMCTL.gotoAndStop("blank");        imagesTL.gotoAndStop(mediaAry[this.index - 1]);    }};


FYI - btnMCTL is a timeline (_global.btnMCTL = this and imagesTL is another timeline (_global.imagesTL = this and have both been tested and are working correctly.

I also have 4 buttons named - btn1, btn2, btn3, and btn4 on the timeline where this frame script exists.

The line of code in question is this:


ActionScript Code:
imagesTL.gotoAndStop(mediaAry[this.index - 1]);


When I replace it with a number like this:


ActionScript Code:
imagesTL.gotoAndStop(mediaAry[0]);


It works, otherwise, it won't work.

Thanks

Sound Loop Code?
So I'm working on my web page and I decided I wanted to add sound to it. I got a loop threw it in my library used some code and some buttons and stuff in a MC. Everything works great except for one thing, after it loops threw once my pause button stops but my play button does not play at all. Here is my code...

Code:
s = new Sound();
s.attachSound("song1");
i=1;
function timeme (){
now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
_root["nowtime"+i] = (Number(hours)*3600)+(Number(minutes)*60)+seconds;
_root.newstarttime = _root["nowtime"+i] - _root.nowtime1;
i++;
}
s.onSoundComplete = s.start
s.start();
timeme();
and on the buttons...

Code:
///pause button///
on(press){
s.stop();
timeme();
}
on(release){
gotoAndPlay(5)
}
///play button///
on(press){
s.stop();
s.start(_root.newstarttime);
}
on(release){
gotoAndPlay (2)
}

How To Shorten This Code Using Loop?
Basically, I have few movieclip [all are same type] which is already on stage.
Note: This movieclip is not added on stage using addChild
In this movieclip, I have many movieclips, given with hex1..hex8 instance name

I wanted to do something like this
hexArray = [hex1,hex2,hex3,hex4,hex5,hex6,hex7,hex8];
and replace the code below with this... but it does not work.

ActionScript Code:
for(var a:int = 0; a<9; a++){for(var b:int = 0; b<8; b++){    var colorFG1:ColorTransform = hcArray[a].hexArray[b].miniHex.hexFG.transform.colorTransform;}



ActionScript Code:
var colorFG1:ColorTransform = hcArray[a].hex1.miniHex.hexFG.transform.colorTransform;    var colorFG2:ColorTransform = hcArray[a].hex2.miniHex.hexFG.transform.colorTransform;    var colorFG3:ColorTransform = hcArray[a].hex3.miniHex.hexFG.transform.colorTransform;    var colorFG4:ColorTransform = hcArray[a].hex4.miniHex.hexFG.transform.colorTransform;    var colorFG5:ColorTransform = hcArray[a].hex5.miniHex.hexFG.transform.colorTransform;    var colorFG6:ColorTransform = hcArray[a].hex6.miniHex.hexFG.transform.colorTransform;    var colorFG7:ColorTransform = hcArray[a].hex7.miniHex.hexFG.transform.colorTransform;    var colorFG8:ColorTransform = hcArray[a].hex8.miniHex.hexFG.transform.colorTransform;

[MX] Array And For Loop Code
Hello,

Is there any reason why this code wouldn't work:


ActionScript Code:
stop();var mediaAry = new Array("audio","downloads","photogallery","video");for (i=1; i<=mediaAry.length; i++) {    this["btn" + i].index = i;    this["btn" + i].onRelease = function() {        gotoAndStop("blank");        btnMCTL.gotoAndStop("blank");        imagesTL.gotoAndStop(mediaAry[this.index - 1]);    }};


FYI - btnMCTL is a timeline (_global.btnMCTL = this and imagesTL is another timeline (_global.imagesTL = this and have both been tested and are working correctly.

I also have 4 buttons named - btn1, btn2, btn3, and btn4 on the timeline where this frame script exists.

The line of code in question is this:


ActionScript Code:
imagesTL.gotoAndStop(mediaAry[this.index - 1]);


When I replace it with a number like this:


ActionScript Code:
imagesTL.gotoAndStop(mediaAry[0]);


It works, otherwise, it won't work.

Thanks

Can You Simplify This Code Using A Loop?
Hi,

can you simplify this code using a loop?

Code:
button1.onPress = function() {
trace("Button1");
};
button2.onPress = function() {
trace("Button2");
};
button3.onPress = function() {
trace("Button3");
};
A simple loop like the one below does not work, as it counts to 4 and then always only displays "Button4".

Code:
for (i=1; i<4; i++) {
_root["button"+i].onPress = function() {
trace("Button"+i);
};
}
There must be a very simple solution for this...
Thanks for your input!

Messy Code Help (for Loop)
Hello All,

I'm looking for a wee bit of help with my code. I've got a bit which runs fine and does what it's supposed to, but it's crying out for a for loop.

I always seem to run into difficulties when I try to make my code efficient when it involves setting onRelease on a bunch of buttons....

Here is a section of the working code in all its lengthiness;


ActionScript Code:
if (picNumber>=2) {
        thumb2_btn.onRelease = function() {
            colourNormal();
            thumb2_mc.brightOffsetTo(-30, .8, "easeoutback", .2);
            tweenFrame(2);
        };
    } else {
        thumb2_btn.useHandCursor = false;
        thumb2_btn.enabled = false;
    }
    //
    if (picNumber>=3) {
        thumb3_btn.onRelease = function() {
            colourNormal();
            thumb3_mc.brightOffsetTo(-30, .8, "easeoutback", .2);
            tweenFrame(3);
        };
    } else {
        thumb3_btn.useHandCursor = false;
        thumb3_btn.enabled = false;
    }
 
etc......etc.....


If the button was on the main timeline I'd try to do _root["thumb"+i+"_btn"].onRelease etc. It's not though.

Anyone point out where I'm going wrong?

For Loop. What Is Wrong Withi My Code?
Hi this is my code:

for (i=1;i<9;i++) {
petalToFade="s03petal0"+i;
_root.preload.s03flower.petalToFade._alpha=0;
}

it's not working. I think the petalToFade=... line is not working. What am i doing wrong?

I want the output to be:
s03petal01
s03petal02
s03petal03
...

so i can make the alpha of several MC equal to 0.

Thanks,
Miguel

Plz Help To Code A Loop Or Sumthin Similar :(
Dear all,

Below is my code for my family picture viewer using external JPEGS

Now I want to add a button for AUTOPLAY... that is, when this button is clicked, the movie keeps going to the next jpeg automatically .
and a companion stop button..

can someone help me with it ?


Thanks
------------------------------------------------------------------
fscommand("fullscreen", "true");
fscommand("showmenu", "false");
fscommand("allowscale", "true");
slides_xml = new XML();
slides_xml.onLoad = startSlideShow;
slides_xml.load("sds.xml");
slides_xml.ignoreWhite = true;
targetClip._alpha = 0;
//
// Show the first slide and intialize variables
function startSlideShow(success) {
if (success == true) {
rootNode = slides_xml.firstChild;
totalSlides = rootNode.childNodes.length;
firstSlideNode = rootNode.firstChild;
currentSlideNode = firstSlideNode;
currentIndex = 1;
updateSlide(firstSlideNode);
}
}
//
// Updates the current slide with new image and text
function updateSlide(newSlideNode) {
imagePath = newSlideNode.attributes.jpegURL;
// added this to create a temp mc that can be removed
// _root.createEmptyMovieClip("temp_mc", -500);
// added this to get the alpha fading to work properly
// _root.temp_mc.onEnterFrame = function()
onEnterFrame = function () {
if (targetClip._alpha>10 && fadeOut) {
targetClip._alpha -= 10;
}
if (targetClip._alpha<10) {
targetClip.square_clip.loadMovie(imagePath);
targetClip2.square_clip.loadMovie(imagePath);
fadeOut = false;
fadeIn = true;
}
if (targetClip._alpha<100 && fadeIn && !fadeOut) {
targetClip._alpha += 10;
}
else {fadeIn = false;}
if (input>30)
{
input = 30;
}
slideText = newSlideNode.firstChild.nodeValue;
styleId = newSlideNode.attributes.ID;};
}
//
//
// Event handler for 'Next slide' button
next_btn.onRelease = function() {
nextSlideNode = currentSlideNode.nextSibling;
if (nextSlideNode == null) {
break;
} else {
updateSlide(nextSlideNode);
currentSlideNode = nextSlideNode;
if (currentIndex<30 && !fadeIn && !fadeOut) {
fadeOut = true;
currentIndex++;
input = currentIndex;
}
}
};
//
// Event handler for 'Previous slide' button
back_btn.onRelease = function() {
previousSlideNode = currentSlideNode.previousSibling;
if (previousSlideNode == null) {
break;
} else {
currentSlideNode = previousSlideNode;
updateSlide(previousSlideNode);
if (currentIndex>1 && !fadeIn && !fadeOut) {
fadeOut = true;
currentIndex--;
input = currentIndex;
}
}
};

Infinite Loop (Code Check)
Trying to make an audio meter. I have 8 columns and 9 rows of LEDs. I have created arrays for updates. The LEDs are a numbered a1-a9, through to h1-h9. When I debug, it goes into an infinite loop and I can not figure out why:
My swf is set for 5 fps and every 5 frames it calls the changeLED function. That doesnt seem like too much of a loadon the CPU to me.

code:
function clearAll(){
for(z=1; z<=9; z++){
_root["a"+z]._visible=0;
_root["b"+z]._visible=0;
_root["c"+z]._visible=0;
_root["d"+z]._visible=0;
_root["e"+z]._visible=0;
_root["f"+z]._visible=0;
_root["g"+z]._visible=0;
_root["h"+z]._visible=0;
}
};

function changeLED(a){
colA=["frame"+a][0];
colB=["frame"+a][1];
colC=["frame"+a][2];
colD=["frame"+a][3];
colE=["frame"+a][4];
colF=["frame"+a][5];
colG=["frame"+a][6];
colH=["frame"+a][7];
for(b=1; b<=8; b++){
if(b==1){
c="a";
colLevel=colA;
}else if(b==2){
c="b";
colLevel=colB;
}else if(b==3){
c="c";
colLevel=colC;
}else if(b==4){
c="d";
colLevel=colD;
}else if(b==5){
c="e";
colLevel=colE;
}else if(b==6){
c="f";
colLevel=colF;
}else if(b==7){
c="g";
colLevel=colG;
}else if(b==8){
c="h";
colLevel=colH;
}
for(d=1; d<colLevel; d++){
_root[c+d]._visible=false;
}
for(d=colLevel; d<=9; d++){
_root[c+d]._visible=true;
}
}
};

//LEDs above number are off, below on
frame1 = new Array("8", "8", "8", "8", "8", "8", "8", "8");
frame2 = new Array("7", "7", "7", "7", "7", "7", "7", "7");
frame3 = new Array("6", "6", "6", "6", "6", "6", "6", "6");
frame4 = new Array("6", "5", "4", "5", "6", "5", "3", "5");
frame5 = new Array("7", "4", "5", "6", "7", "4", "2", "4");
frame6 = new Array("8", "5", "6", "7", "6", "3", "1", "6");
frame7 = new Array("7", "4", "5", "7", "4", "1", "3", "4");
frame8 = new Array("6", "3", "4", "6", "8", "5", "2", "2");
frame9 = new Array("7", "4", "5", "8", "9", "4", "4", "6");
frame10 = new Array("8", "5", "6", "7", "7", "3", "1", "7");
frame11 = new Array("9", "6", "7", "6", "5", "1", "5", "4");
frame12 = new Array("7", "4", "4", "4", "7", "3", "2", "6");
frame13 = new Array("6", "5", "4", "5", "6", "2", "4", "1");
frame14 = new Array("6", "4", "3", "5", "8", "5", "2", "5");
frame15 = new Array("5", "7", "9", "4", "9", "4", "1", "8");
frame16 = new Array("5", "6", "6", "4", "7", "6", "2", "6");

Making Code For MC Loop FASTER
ok...

3 MCs...

1 large PIC inside a movie clip 1 frame... instance: graphix
1 small MC with nothing in, instance: arrow
1 small MC with 2 frames of CODE

in the CODE MC.. i have this code

FRAME 1:

difference = _ymouse-_parent.arrow._y;
delay = 2;
_parent.arrow._y = _parent.arrow._y+(difference/delay);
_parent.graphix._y = -_parent.arrow._y;


FRAME 2:

gotoAndPlay (1);


==========================================
due to the large pic.. the FPS get laggy as does the MC with the code...

is there any way that I can attach this code somewhere else where it will play faster?

thanks A MILLION IN ADVANCE

-manny
www.mannymedia.com


EXAMPLE OF WHAT IM TRYING TO DO: http://www.frostdesign.co.uk/ go to ZEMBLA then ZEMBLA MAGAZINE

Frame Loop Code Lockup
Does anyone know if a loop for(i=0; i<=50; i++)is placed on a frame so that it executes each time the frame loops, will drastically slow down a movie, cause it to lockup?

Likewise, if a loadVarible("file.cgi, ""); placed on the same frame so that it also retreives this value multiple times, will this code placement arragement lock up a ssystem?

I could place the code on a movieclip utilizing the onClipEvent(load) fucntion but I don't want to change things if I don't have to.


Any help will be greatly appreciated.



iaustin

Assiging Button Code With For Loop
I have lots of buttons that share similar code but all have a unique variable to operate.

instead of coding

Code:
//button functions
b1.onRelease=function(){
gotoAndPlay(1)
}
b2.onRelease=function(){
gotoAndPlay(2)
}
b3.onRelease=function(){
gotoAndPlay(3)
}
b4.onRelease=function(){
gotoAndPlay(4)
}

//etc etc etc
{

I thought it would be alot tidier/slimmer to create a for loop to write the button code.

such as...


Code:
for(i=0;i<56;i++){
this["b"+i].onRelease=function(){
gotoAndPlay(i)
}
}

This is all good but as you can probably see, all butts point to the same frame (55) as "i" is incremental and global.

So my question is: how do I create a unique variable in a for loop in the above example?

Many thanks for any help

Help To Compress Code Into Loop/arrays
I have been working on this for about 2 hrs, Im trying to think of a way to compress all the code I have so far into about 3 loops/arrays.

I have 20 instances of the same button that will be added to the stage, call it car_btn. Then I have an xml file where Im grabbing the nodes using an index number ex: [3]. Then I have 20 instances of the same popup_mc, all of the buttons pull data from an xml file and populate this popup_mc.

here is my code, anyone know how to simplify all of this into a series of arrays/loops. I want to make it so its not adding just one instance of the popInfo - but one for each button that is clicked.


Code:
// variables
var popInfo:popMc;
// var urlNY = xml.city[0].@weburl.toString(); //trying to get this variable to work

// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("data/cities.xml"));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
trace(xml.city[0].@weburl.toString());
}
);


// event listeners
seattleBtn.addEventListener(MouseEvent.CLICK, onClickSEA);
losangelesBtn.addEventListener(MouseEvent.CLICK, onClickLA);

// functions
function onClickSEA(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[1].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[1].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[1].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[1].@name.toString();
}

function onClickLA(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[2].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[2].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[2].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[2].@name.toString();
}


function onClickRemove(event:MouseEvent):void
{
removeChild(popInfo);
}

function onClickNYOP(event:MouseEvent):void
{
navigateToURL(url, "_blank");
// navigateToURL(urlNY, "_blank"); //trying to get this variable to work

}

// set button mode here
seattleBtn.buttonMode = true;
losangelesBtn.buttonMode = true;

Basic Code Problem - (for Loop)
I know its a simple problem, but i cant figure it out


PHP Code:



for (i=1; i<6; i++) {
    sItem = ("s"+i);
    sItem._x = Math.random((bR._x), (tL._x))*(bR._x);





where my mc's are s1..s5

~ Lacuna aka Seretha

Help Understanding Why This Code Works - For Loop
I have 4 buttons on the stage. I want to assign each button a unique action by using a for loop to assign the actions to these buttons
This example does not work:

PHP Code:



for (i=0; i<4; i++) {
    this["btn"+i].onRelease = function() {
        trace("this"+[i]);
    };





each button traces "this4"


this example does work!

PHP Code:



for (i=0; i<4; i++) { 
        myBtn = this["mybtn"+i]; 
        myBtn.num = i; 
        myBtn.onRelease = function() { 
            trace(this.num); 
        }; 
    } 




each button traces properly.


what I want to know is why, I'm happy that I got this code to work at all, but I would really like to know why the bottom one works, and the top doesn't, so I at least learn from this.
My guess is that it has to do with the incrementing variable ("i") inside the for loop, but I just want to be clear on this.

thanks

Play Frames In Loop With Code.
Hello all.
In my project i need a code wich allow me to play an animation (not a motion tween)
it is a self hand made animation frames by frames.
my animation start from frame 10 and finish in frame 15.
I just need to play it from 10 to 15 in Loop when my mouse is over.
and stop animation loop when my mouse is out.
i hope i am clear in my description.

thx a lot bye !

Basic Code Problem - (for Loop)
I know its a simple problem, but i cant figure it out


PHP Code:



for (i=1; i<6; i++) {
    sItem = ("s"+i);
    sItem._x = Math.random((bR._x), (tL._x))*(bR._x);





where my mc's are s1..s5

~ Lacuna aka Seretha

Help Understanding Why This Code Works - For Loop
I have 4 buttons on the stage. I want to assign each button a unique action by using a for loop to assign the actions to these buttons
This example does not work:

PHP Code:



for (i=0; i<4; i++) {
    this["btn"+i].onRelease = function() {
        trace("this"+[i]);
    };





each button traces "this4"


this example does work!

PHP Code:



for (i=0; i<4; i++) { 
        myBtn = this["mybtn"+i]; 
        myBtn.num = i; 
        myBtn.onRelease = function() { 
            trace(this.num); 
        }; 
    } 




each button traces properly.


what I want to know is why, I'm happy that I got this code to work at all, but I would really like to know why the bottom one works, and the top doesn't, so I at least learn from this.
My guess is that it has to do with the incrementing variable ("i") inside the for loop, but I just want to be clear on this.

thanks

The Loop Code I Wrote Doesn't Seem To Work
I am trying to right a loop, but it doesn't seem to be working. Can anyone help?


What I want the loop to do is loop 16 times producing 16 lines of code that look like this.

cat1questions.data.question1 = question1.text = "Add Question In Admin";
cat2questions.data.question1 = question2.text = "Add Question In Admin";
cat3questions.data.question1 = question3.text = "Add Question In Admin";
cat4questions.data.question1 = question4.text = "Add Question In Admin";. . . and so on n so on

Here is the loop code I created. When I do a trace the loop works fine, but I haven't got the proper syntax to produce the lines of code that I need.

function onResetQuestions() {
var textStr = "";
var questStr = "";
var i = 0;
while (++i <= 16) {
textStr = "cat" + i + "questions.data.question1" + questStr;
questStr = "question" + i + ".text";
textStr = questStr = "Add Question In Admin";
test.text = textStr = questStr = "Add Question In Admin";
}

Thanks for any help!

Loop For Rotation And Scaling - AS Code Check
Good day to all of you Flashers,

I'm trying to make a MC rotate 5 (five) times and enlarge it with each iteration. After 5 rotations the MC should stop and the visitor is redirected to another page.
So far I've constructed this code:

onClipEvent(enterFrame) {
for (i = 0; i <5; ++i) {
this._rotation += 10;
this._xscale = this._xscale + 1;
this._yscale = this._yscale + 1;
}
}

The rotation works fine, and the size of the MC gets enlarged.
BUT THE ROTATIONS DOES NOT STOP AFTER 5 ROTATIONS!!!
I guess I must be doing something wrong somewhere...

Can somebody finish this code for me?
Thanks

Dubya

Music Loop Code Done - How To Make On / Off Button?
I've used this code to loop my music....

var my_sound = new Sound();
my_sound.loadSound("sound.mp3", true);
my_sound.setVolume(10);
my_sound.onSoundComplete = function() {
my_sound.start();
}

How can I make an on / off button for the music now?

Thanks a lot

[F8] Code Causing Infinite Loop Proglem :(
Hi there, as usual my problem is hard to explain but I will try...

Ive downloaded this great flv player from the movies section of flashkit which works fine. Now ive incorporated it into my site I have it pulling in varios flvs according to which section you're in...

now...

the following code works fine, but if I click between sections (thus reloading the frame the script is on) BEFORE the "loading ..." text has left the screen, the loaded flv gets stuck in the in an infinite loop (intervalID = setInterval). If I wait until the "loading..." text has left the screen to change sections (thus reloading this script) all works fine.

As you can probably guess, Im not a coder, but Ive tried my hardest to try and fix this by clearing intervals and tracing things to see whats going on -but with no luck

If anybody could help me with this it would be sooo appreciated

many thanks!






//--------------------------------------------------------------------------
// controlbar functionality
//--------------------------------------------------------------------------
// play the movie and hide playbutton
function playMovie() {
if (!isStarted) {
ns.play(file);
//stop the movie until enouth data has been downloaded
pauseMovie();
//retrieve the bitrate
t0 = new Date().getTime();
intervalID = setInterval(function (obj) {
var loaded = obj.ns.bytesLoaded;
var total = obj.ns.bytesTotal;
var duration = parseInt(obj.ns.totalTime);
var confidence = obj.confidence;
//for better inference let's laod at least 25KB of video before calculating any estimation
// and let's have duration retrieved
if (loaded>25*1024 && typeof duration != "undefined" && !isNaN(duration)) {
var now = new Date().getTime();
your_bitrate = loaded/(now-t0)*1000;
// loadingTime = time required to download the video - duration - time elapsed
loadingTime = total/your_bitrate-duration-(now-t0)/1000;
loadingTime = (loadingTime>0) ? Math.ceil(loadingTime*confidence) : 0;
ns.setBufferTime(loadingTime);
if (loadingTime == 0) {
ns.play(file);
clearInterval(intervalID);
}
}
}, 50, this);
playText.txt.text = "loading ...";
isStarted = true;
} else {
ns.pause();
}
pauseBut._visible = true;
playBut._visible = false;
videoDisplay._visible = true;
imageClip._visible = false;
}

Creating OnRelease Code With Arrays And A Loop
I feel stupid for asking this, but I have no idea why this is not working.

buttonLINKS = [1,2,3,4];
buttonsArray = [navigation.menu.A,
navigation.menu.B,
navigation.menu.C,
navigation.menu.D];

And this is what I wrote....

Code:
for (i=0;i<buttonsArray.length;i++) {
buttonsArray[i].onRelease = function() {
loadThis(buttonLINKS[i]);
}
}

Stop My Infinite Random Loop Code
I'm making a "magic 8 ball" Flash gadget and I'm having some problems getting the code to randomly select 1 of the 10 pre assigned answers and having it stay with that answer. It keeps renewing the code for some reason and resubmitting a new random entry.

here's the code theory i got running:


ActionScript Code:
onClipEvent (enterFrame) {
randomX = Math.ceil(Math.random()*10);
if (randomX == 1) {
gotoAndStop ("a1");
} else {
... etc...

My answers are in a 10 frame movie clip with labels "a1" through "a10"

So why wont it just goto and stop at one and stay with it?

Problem Button.rollOver Code In For Loop
I have three movieclips (used as buttons) on my main MC. The following code swaps the depth of a dynamically loaded image the when I rollOver each movieclip (button).

I want to put the button.rollOver code in a for loop so I dont have to repeat this code for every image loaded.


ActionScript Code:
x = 150; // x location of imageY = 100; // y location of imageonLoad = function () { _global.nextDepth = 1; _global.displayed = 0;};// Import photosfor (i=1; i<8; i++) { this.createEmptyMovieClip("clip"+i+"_mc", i); this["clip"+i+"_mc"].createEmptyMovieClip("photo_mc", 0); this["clip"+i+"_mc"]["photo_mc"].loadMovie("pics/pic"+i+".jpg"); // put the movieclip at x znd y locations this["clip"+i+"_mc"]._x = x; this["clip"+i+"_mc"]._y = y; // scale photos this["clip"+i+"_mc"]["photo_mc"]._xscale = 100; this["clip"+i+"_mc"]["photo_mc"]._yscale = 100; button1.onRollOver = function() {  if (displayed != 1) {   nextDepth = _root.getNextHighestDepth();   clip1_mc.swapDepths(nextDepth);   displayed = 1;  } } button2.onRollOver = function() {  if (displayed != 2) {   nextDepth = _root.getNextHighestDepth();   clip2_mc.swapDepths(nextDepth);   displayed = 2;  } } button3.onRollOver = function() {  if (displayed != 3) {   nextDepth = _root.getNextHighestDepth();   clip3_mc.swapDepths(nextDepth);   displayed = 3;  } }}

Code Breakdown In For Loop. Array Syntax.
I've got this loop and can't get it to work. It won't read the trace so I know the array call in my function statement is wrong but I can't see it at the moment. What am I doing wrong here? The rollover works when I write it out repetitively for the four buttons. Thanks for the help.

var btnAction:Array = new Array (oneBut, twoBut, threeBut, fourBut);
for (var i=0; i<btnAction.length; i++) {
this.menuMC.btnAction[i].onRollOver = this.menuMC.btnAction[i].onDragOver = function() {
trace("anything");
}
};

Problem Button.rollOver Code In For Loop
I have three movieclips (used as buttons) on my main MC. The following code swaps the depth of a dynamically loaded image the when I rollOver each movieclip (button).

I want to put the button.rollOver code in a for loop so I dont have to repeat this code for every image loaded.


ActionScript Code:
x = 150; // x location of imageY = 100; // y location of imageonLoad = function () { _global.nextDepth = 1; _global.displayed = 0;};// Import photosfor (i=1; i<8; i++) { this.createEmptyMovieClip("clip"+i+"_mc", i); this["clip"+i+"_mc"].createEmptyMovieClip("photo_mc", 0); this["clip"+i+"_mc"]["photo_mc"].loadMovie("pics/pic"+i+".jpg"); // put the movieclip at x znd y locations this["clip"+i+"_mc"]._x = x; this["clip"+i+"_mc"]._y = y; // scale photos this["clip"+i+"_mc"]["photo_mc"]._xscale = 100; this["clip"+i+"_mc"]["photo_mc"]._yscale = 100; button1.onRollOver = function() {  if (displayed != 1) {   nextDepth = _root.getNextHighestDepth();   clip1_mc.swapDepths(nextDepth);   displayed = 1;  } } button2.onRollOver = function() {  if (displayed != 2) {   nextDepth = _root.getNextHighestDepth();   clip2_mc.swapDepths(nextDepth);   displayed = 2;  } } button3.onRollOver = function() {  if (displayed != 3) {   nextDepth = _root.getNextHighestDepth();   clip3_mc.swapDepths(nextDepth);   displayed = 3;  } }}

Copyright © 2005-08 www.BigResource.com, All rights reserved