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




Dynamic For In Loop?



I need to set a dynamic value as part of a for..in loop.
Flash is hissing at me when i do the stuff below


Code:
function getServiceCode_Result(sct_availability) {
//trace("serviceCode"+eval(serviceCode))
for (eval(service_code) in sct_availability) { //< this doesn't work
name = sct_availability[eval(service_code)].name;
price = sct_availability[eval(service_code)].date;
myDate = sct_availability[eval(service_code)].price;
lable = name + " " + price + " " + myDate
sendToTree(lable);
}
}

any ideas?



FlashKit > Flash Help > Flash MX
Posted on: 10-09-2002, 03:47 PM


View Complete Forum Thread with Replies

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

Loop And Dynamic Txt Help
I have a dynamic txt box loaded into a flash page. when i click a button on the side bar it loads another external txt into the dynamic txt box. what i want to know is how is it possible to format the txt file? Is it possible to load an html file? or are there special formating tags that i can use?

I also had tried to implement the scrollbar into the dynamic txt field but the way i have done things means that the loadtext command screws things up. So i resulted to making two more buttons and using the following code to make the text scroll up and down when the user clicks them.

on (rollOver) { textField.scroll=textFieldscroll + 1
}

Now this works fine but i want to loop this command so that if the mouse is still rolled over then the text continues to scroll and when it is rolled off the button it stops scrolling the text. Ive tried using for, if and do while commands but i cant seem to get it to work without it just jumping to the end of the page or creating an infinit loop that causes a crash.

Dynamic Loop
Code:
while(count<numOfPics)
{
lastClip = dupMovName+(count-1);
thisClip = dupMovName+count;

position = Math.round(Number(lastClip:_x)+picSize);

this[thisClip]._x = Number(lastClip:_x);

count++;
}
What this code is supposed to do is set the position of images with a name, which is composed of dupMovName (is set as: "clipart") and the according number (so I have clipart1,clipart2...and so on), to the position of clipart1+100 (=picSize).
The number of images is variable so I need some sort of loop to cover al the images, but (I am a beginner) I don't know the syntax do get this done.
I tried it a few hundred ways around, but no luck yet...

Suggestions anyone?

Dynamic XML Loop
Flash Masters,

I hope you can help me out. I am trying to dynamically add text fields based on the XML length. I can get the loop to work just fine with addChild based on the lenght but when I add in the XML date I get an error. Error #1010: A term is undefined and has no properties.

Ive tracked it down to this line of code

this["hempDate_txt"+i].text = list[i].hempDate

Any ideas of how to make this work?
EDIT
Thank you for all the help But I figured I needed to just change it too
tField1.text = list[i].hempDate;

Thanks


Chad

Dynamic Loop
Hello every one I am Trying to animate a movie clip from left to right, and I need the movie clip to detect when it has meet the half way point and then duplicate itself to the end of the movie clip so that i receive a continues loop without having to use a massive amount of frames.

if any one could help with this it will be very much appreciated.

Dynamic While Loop
Hey

I am creating an internal search engine for my website

I need to display the results and want a button for each result. Now i have my button in the library and i know how to attach it using attachMovieClip. I am struggeling to get it to load in multiple buttons.

Now what i have done so far is to create a emptyMovieClip
Then set its x and y Values
Then i start my while loop and create another empy movielip in that and then attach the button inside that clip. The reason i create another empty clip is so that i can movie that clip to the next y value.
Could someone please have a look at my code and give me a few pointers?


PHP Code:





// Start of doSearch Function
function doSearch(search) {
    count = search.length;
    SearchResultsDepth = 3000;
    moreClipDepth = 1999;
    moreClipButtonDepth = 1500;
    i = 0;
    j = 0;
    searchXvalue = 110;
    searchYvalue = 140;
    // Create Empty Clip For Buttons
    _root.createEmptyMovieClip("more", 2000);
    _root.more._y = 150;
    _root.more._x = 80;
    moreClipX = 80;
    moreClipY = 150;
    while (count>=1) {
        // createTextField (instanceName,depth,x,y,width,height)
        createTextField("searchResultsTitles", SearchResultsDepth, searchXvalue, searchYvalue, 300, 25);
        _root.searchResultsTitles.text = search[i];
        searchResultsTitles.setTextFormat(homepageArticlesTitles);
        searchResultsTitles.selectable = false;
        // attach the buttons
        moreClip = "Clip"+j;
        MoreButton = "Button"+j;
        _root.more.createEmptyMovieClip(moreClip, moreClipDepth);
        _root.more.moreClip._y = moreClipY;
        _root.more.moreClip.attachMovie("OverviewButton", MoreButton, moreClipButtonDepth);
        // change the function values(text Related)
        count--;
        i++;
        j++;
        SearchResultsDepth--;
        searchYvalue = searchYvalue+25;
        // change the function values(Button Related)
        moreClipDepth--;
        moreClipButtonDepth--;
        moreClipY = moreClipY+25;
    }
}
// End of doSearch Function 







This does not actually create any button. I have a feeling that it has to do with the moreClip variable.

Any help or tutorials would be appreciated

Hanu

Dynamic Motion Loop
anybody knows how to loop a scrolling symbol on the scene,
i have this code on my symbol.


onClipEvent (load) {
this._x = 50;
}
onClipEvent (enterFrame) {
this._x = this._x+5;
}


but i cannot loop it.

For I In Loop And Dynamic Variables
hi,
I can create dynamicly variables but how can I ge the values?
my trace action doesnt give me the values
has somebody an idea?

// <code>

var cnt = 0;
for (var i in nav_mc) {
nav_mc[i]["movie"+cnt] = cnt;
nav_mc[i].onRelease = function() {
//trace(this["movie"+cnt])
};
cnt++;
}
// <endCode>


//----------------------------------------------------
// OUTPUT WINDOW:
//----------------------------------------------------
Variable _level0.nav_mc.myClip1_mc.movie1 = 1
Variable _level0.nav_mc.myClip1_mc.onRelease = [Funktion 'onRelease']
Movieclip: Ziel="_level0.nav_mc.myClip2_mc"
Variable _level0.nav_mc.myClip2_mc.movie0 = 0
Variable _level0.nav_mc.myClip2_mc.onRelease = [Funktion 'onRelease']

Loop A Dynamic Loaded Mp3
can you? cause it won't work for me..

Dynamic For Loop In Mx2004
I'm using Flash MX2004 and actionscript 2.0

Using the following code I'm able to make the movieclips within an instance of the symbol "pan" on the stage go to various frames named "pan".

function initiate(character1:String):Void {
this.onEnterFrame = function() {
_root[character1].head.head_sub1.gotoAndPlay(character1);
_root[character1].head.feature.gotoAndPlay(character1);
_root[character1].body.gotoAndPlay(character1);
_root[character1].head.ear_r.gotoAndPlay(character1);
_root[character1].head.ear_l.gotoAndPlay(character1);
_root[character1].arm_r.gotoAndPlay(character1);
_root[character1].arm_l.gotoAndPlay(character1);
_root[character1].leg_r.gotoAndPlay(character1);
_root[character1].leg_l.gotoAndPlay(character1);
};
}
initiate("pan");

However I am unable to figure out how to put in multiple parameters at once. I tried the following function but run into the problem that flash is looking on the stage for an instance of "character1" and "character2" when it should be looking for instances of the value of character1 and character2.

function initiate(character1:String, character2:String):Void {
var total_characters:Number = 2;
this.onEnterFrame = function() {
for (i=1; i<=total_characters; i++) {
_root["character"+i].head.head_sub1.gotoAndPlay(["character"+i]);
_root["character"+i].head.feature.gotoAndPlay(["character"+i]);
_root["character"+i].body.gotoAndPlay(["character"+i]);
_root["character"+i].head.ear_r.gotoAndPlay(["character"+i]);
_root["character"+i].head.ear_l.gotoAndPlay(["character"+i]);
_root["character"+i].arm_r.gotoAndPlay(["character"+i]);
_root["character"+i].arm_l.gotoAndPlay(["character"+i]);
_root["character"+i].leg_r.gotoAndPlay(["character"+i]);
_root["character"+i].leg_l.gotoAndPlay(["character"+i]);
}
};
}
initiate("pan", "polar");

Any help would be greatly appreciated,
lkress

How Can I Loop Dynamic Loaded Mp3?
hello friends

i have loaded external mp3 with folloing code


Code:
loop1 = new Sound();
loop1.loadSound("mp3/track1.mp3");
but dont know how to loop

i want to load this mp3 file in start

so when movie is start to play.. it automatically play and yes in loop

please help me

thanks

Dynamic Loop Loader
Hi, I'm working on some sort of dynamic loop loader.

The idea is that you have several loops who can follow up each other.
The first loop is played streaming, when started playing, loop 2 should start loading (invisible).

loop 1 repeats till loop 2 is fully loaded, at the end of the last loop 1 it should be followed by the loaded loop 2

now that loop 2 has started to play, it should start to load loop 3(invisible)

When loading loop 3 has finished and an instance of playing loop 2 has came to a loop-point, loop 3 should start playing.

....
the last loop should be follewed again by loop 1, loop2, loop 3, loop 4 ... loop1 (because all loops are preloaded at that time)

the basic idea after it is that the music constantly evolves, while downloadtime is balanced ...

This is the code I have now;it has the basic system (it works) !
The only problem is that all loops start preloading (sx.loadSound ) at the same point


In frame 1 i have

Code:
s1 = new Sound();
s2 = new Sound();
s3 = new Sound();
now I use this code in frame 2

Code:
s3.onSoundComplete = function() {
s1.start(0, 1); // loop 3 done ? -> start over @ loop 1
};
s2.onSoundComplete = function() {
if (s3.getBytesLoaded()>=s3.getBytesTotal()) {
s3.start(0, 1); // if s3 loaded; start playing
} else {
s2.start(0, 1); // else repeat s2 till s3 has been loaded
}
};
s1.onSoundComplete = function() {
if (s2.getBytesLoaded()>=s2.getBytesTotal()) {
s2.start(0, 1); // if s2 loaded; start playing
} else {
s1.start(0, 1); // else repeat s1 till s2 has been loaded
}
};
s1.loadSound("./dropper.mp3",true);
s2.loadSound("./dropper2.mp3");
s3.loadSound("./dropper3.mp3");
Ive tried already this option

Code:
s1.onSoundComplete = function() {
s2.loadSound("./dropper2.mp3");
if (s2.getBytesLoaded()>=s2.getBytesTotal()) {
s2.start(0, 1);
} else {
s1.start(0, 1);
}
};
but unsuccesfull.
I shoud be able to detect if s2.loadSound already has been called

Sorry for my bad english, hope you understand me.

thx in advantage

Dynamic Buttons Loop
I need 150 buttons, each loading a different jpg. So I'm trying to use duplicate movie to create the buttons and add also add the script. The code below creates the buttons and spaces them fine...


Code:
while (i<=150) {
duplicateMovieClip("button_mc", "button_mc"+i, _root.getNextHighestDepth());
_root["button_mc"+i].onRollOver = function(){
_root["button_mc"+i].useHandCursor=true;
}

_root["button_mc"+i]._x = baseX + mcW*((i-1)%ipr);
_root["button_mc"+i]._y = baseY + mcH*int((i-1)/ipr);
i++
}
but when i add this bit of code (after the first function):

Code:
_root["button_mc"+i].onPress = function(){
_root.sofaClip.armL.armL_btn.onPress = function() {
img_mcl.loadClip("images/"+i+".jpg", _root.sofaClip.armL.container);
}
}
when I test the movie, any button i press i get a message saying:
Error opening URL "file:///images/151.jpg"

I think I am adding the code in the wrong place i.e. after the variable i is 150, meaning that this part: "images/"+i+".jpg" brings back 151.jpg

Any suggestions would be really appreciated.
Thanks.

Loop For Dynamic TextFields
Hi,

Trying to create text fields... 10 rows, 4 in each row.

This doesn't throw an error...

for(var i:Number=0; i<contentArray.length; i++){
for(var j:Number=1; j<5; j++){ this.createTextField("textField"+i+j,i+j,i*30,j*30 ,100,30);
}
}


But Debug > Objects shows that it only creates 4 across on the last j loop:

Target="_level0.textField01"
Target="_level0.textField11"
Target="_level0.textField21"
Target="_level0.textField31"
Target="_level0.textField41"
Target="_level0.textField51"
Target="_level0.textField61"
Target="_level0.textField71"
Target="_level0.textField81"
Target="_level0.textField91"
Target="_level0.textField92"
Target="_level0.textField93"
Target="_level0.textField94"


Stupidity... or ???

thx.

Dynamic Loop Xml Attributes
Hi there,

does anyone maybe knows if there is a possibillity to dynamicly loop threw xml node attributes?

so i can get out the amount of the node attributes (like length of an array) the attribute names and the attribute values? i tried several things but cant find a way...

if this isnt possible, is there maybe an easy way to convert all node attributes in an array?

thanks alot!

Flash Dynamic Loop Help
Hey all,

i've currently got php looping out a reply to flash in a query string form like below,

amountOfVars=3&var1=alex&var2=welcome&var3=helloag ain

all is fine in the php stage, but when i get to flash and try to get flash to loop the vars back out i run into a problem, e.g.


ActionScript Code:
var replyData:URLVariables = new URLVariables(urlLoader.data);
var i:Number = 0;
           
while(i < replyData.amountOfVars) {
    comboBox.addItem({label:replyData.var1});
    i++;
}

As seen above, this code loops out the same var1, 3 times, what i cant work out is how to get the loop to change the replyData.var, to a var2 and var3

Everything i try seems to reply with NaN, nothing at all, or undefined.

Sorry if this is a little confusing :P

Thanks in advanced,
alex

Dynamic Button In For Loop? Help Please
Hello,

I have 10 movieclips that I want to assign this button function to:

vest01_mc.onRollOver = function () {

TweenLite.to(this, 1, { _brightness:40, ease:Regular.easeOut, delay:0});
}

Instead of writing functions for all 10 clips I thought I could use a For Loop (code pasted below) but it doesn't seem to work. I think it's because "vestMc" is a string not an object. Is there a way to convert a string to an object or is there some other way to write this code and achieve the same results?

for (i=1;i<11;i++){

vestMc = "vest" + i + "_mc";

vestMc.onRollOver = function () {

TweenLite.to(this, 1, { _brightness:40, ease:Regular.easeOut, delay:0});
}

vestMc.onRelease = function () {

vestNum = 1;
bgFade("vestDetail");
}

vestMc.onRollOut = function () {

changeOptionColor(this, outColor);

}

}

thanks so much!

Dynamic Vars In For Loop
Hi, I have created a movieclip. This movieclip will have 5 child Sprite's, which will contain an image pulled from xml.

I want to create a for loop to create those 5 Sprite's, add the appropriate image into each one (i.e., img[0] into sprite[0]) and then add each sprite to the movieclip.

Here is how I'm failing to do it...


ActionScript Code:
//    var xmlImgHolder_1:Sprite = new Sprite();
//    var xmlImgHolder_2:Sprite = new Sprite();
//    var xmlImgHolder_3:Sprite = new Sprite();
//    var xmlImgHolder_4:Sprite = new Sprite();
//    var xmlImgHolder_5:Sprite = new Sprite();
       
        for (var i:uint = 0; i < xmlData.length; i++){
            var xmlImgHolder_[i * 1]:Sprite = new Sprite();
        }

is there another way?

OR... perhaps can I create 1 Sprite, instantiate it and call it by name?

Using Dynamic Variable Name In A Loop... How?
i am totally unsure of what i am doing wrong and whether this is even possible.
how do i loop the NAME of the variable? (not the contents)

i have 10 variables in movie clip 'myMovie' called pos1,pos2... up to pos10.
i want to loop those names in a 'for' script adding 'newVariable' to each.
something like this:

for (var a = 1; a<11; a++) {
"myMovie.pos"+a = newVariable;
}

basically i want the variable name to loop through myMove.pos + the numbers 1 -10 and in each of these variables will be "newVariable"

i keep trying to use either eval or whatever and everything seems to throw an error saying that a variable or property must be used to the left of the = sign.

anyways hope this makes sense
any help.... please....

Dynamic Function In For Loop...Possible?
Just like it says. I've made a Biology Dictionary that uses an array to access the necessary information to display. From there I made a movieclip which contains more movieclips that act as buttons for displaying the information.

Now from there I realized that I would have to do something like

ActionScript Code:
_root.scroller.scroll0_mc.onRelease=new function(){
_root.descrip_txt.text=_root.descriptions[0];
for each and every buttons code. Now I could do that, but I don't want to have to write that same code again and again with only minor alterations (Yes I know of Ctrl+C and Ctrl+V)

So is there any way I could automate that bit of code via a for loop?

Thanks in advance.

Dynamic MC Creating In For Loop
can someone please explain to me how I can create a movieclip, then create n children to the movieclip. In the following code, if i use 'this' instead of a mc id [matrix] then it works, but when i try to createEmptyMovieClip using matrix. the children are overwritten.

What I want to acheive is one movie clip with n children that i can move and all its children will move in unison, and another mc that sits in a static position above the moving clip.


thanks,
Maurice









Attach Code

// this code produces 9 clips but on the root level
for (var i = 0; i < 9; i++)
{
var mc = this.createEmptyMovieClip('clip_' + i, getNextHighestDepth());
}

// this code produces one clip inside the matrix clip
// what i want is 9 clips inside the matrix clip
matrix = this.createEmptyMovieClip('matrix', getNextHighestDepth());
for (var i = 0; i < 9; i++)
{
var mc = matrix.createEmptyMovieClip('clip_' + i, getNextHighestDepth());
}

Loop Over Dynamic Text Box?
Hi Guys:
How do I loop some text over a dynamic text box.

I have a dynamic text box called (dyntext). I have a button below that Says "Click Here" or something to that effect.

Now, when I Click on the button, I have some code like

var i
for(int i=0;i<25;i++) {
dyn.text="this is a test";
}

but no dice. it only writes it once. not the 25 times like I want. it works in trace("message") but why not in a dynamic text box.

thanks guys.

jeyyu.

Dynamic Rotation Loop
I am trying to loop through a conditional and rotate movie clips dynamically.  My code (that doesn't work) is the following :

function getData_Result(result) {
    _root.relations_ds.dataProvider = result;
    angelDiv = Number(360/_root.relations_ds.dataProvider.length);
    for (g=0; g<_root.relations_ds.length; g++) {
        toRotate = String(Number(angelDiv * g));
        eval("_root.stem"+g+"_mc._rotation = '120'");
    }
}

The problem is with the eval function.. doesn't rotate anything. I'm sure this is just a syntax error, but I can't figure out how to get it to work.

Dynamic _y Spacing In A Loop
is it possible to have a dynamic _y spacing between movieclips of different heights attached using a loop?

Dynamic Sound Loop?
Hi Guys

So I have a dynamic sound loaded into my scene.

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

How do I make the sound loop? once it's there.

Many thanks

Bana

[flash 4] While Loop And Dynamic Variables
Hi...

I've got a problem with some variables I use in my flash 4 (yes 4) movie.

I load a php script which returns the following: w1=hello&w2=world etc...it can go up to w250 (there is a variance)

These variables need to be used in the movie later on.
I do a while loop with the following code:

Loop While (a<=9)
Set Variable: "b" = a+1
Set Variable: "rw" = "word"&b
Set Variable: "ww" = "w"&b
Duplicate Movie Clip ("/word", rw, b)
Set Property (rw, X Position) = "10"
Set Variable: "y" = 33+(18*b)
Set Property (rw, Y Position) = y
Set Variable: "a" = a+1
Set Variable: rw&":n" = ww
End Loop

The loop goes ok but I have one problem with the line:

Set Variable: "ww" = "w"&b

when I enter

Set Variable: "ww" = w3

it shows the right content (out of variable w3, returned from the phpscript) but I can't seem to figure out the way to loop through it the way I want (as above)

Any ideas?

thx

Setting RollOver Fns On Dynamic MCs, Within A Loop
Something is amiss.

I have duplicated MCs, using loaded data and a loop. When the "spot" in the MC is rolled over, two text boxes appear. They vanish on rollout. Well, that's the idea.

It works if I do the following script minus the loop... with just say, i=1. But when I loop it, the "spots" in the different MCs don't make visible their own text boxes... they all trigger the same one: the last one. (Actually, they attempt to trigger one after the last one, if there were another. I had to mess around a lot before I figured that much out. That's why "(i-1)" is there instead of "i", so I could see what was happening.)

I assume I can't set this up this way then. How would I achieve the same effect? Thanks for any ideas...


Code:
varReceiver = new LoadVars();
varReceiver.load("fetchmapdata.php");
varReceiver.onLoad = function(){
var numspotsVar = this.numspots;
for (var i = 0; i < numspotsVar; i++) {
duplicateMovieClip("textbox", "textbox"+i, i);
_root["textbox"+i]._x = this["xx"+i];
_root["textbox"+i]._y = this["yy"+i];
_root["textbox"+i].DyText.text = this["textVar"+i];
_root["textbox"+i].DateText.text = this["dateVar"+i];
_root["textbox"+i].DyText.autoSize = "center";
_root["textbox"+i].DyText.background = true;
_root["textbox"+i].DyText.backgroundColor = 0xaaccdd;
_root["textbox"+i].DyText.wordWrap = true;
_root["textbox"+i].DyText._visible = false;
_root["textbox"+i].DateText.background = true;
_root["textbox"+i].DateText.backgroundColor = 0xaaccdd;
_root["textbox"+i].DateText._visible = false;
_root["textbox"+i].spot.onRollOver = function () {
_root["textbox"+(i-1)].DyText._visible = true;
_root["textbox"+(i-1)].DateText._visible = true;
}
_root["textbox"+i].spot.onRollOut = function () {
_root["textbox"+(i-1)].DyText._visible = false;
_root["textbox"+(i-1)].DateText._visible = false;
}
}
}

Dynamic Sound: Loop Control
hi,

i'm trying to loop some seperate music tracks and mute the sounds individually by buttons- a bit like a mixer or sequencer. i'm loading them from the library using attachsound and looping them using onsoundcomplete which is fine if the loops are all exactly the same length but what about if i want to sync a sound that is not as long as the whole loop to only play at the beginning of the loop? eg. a cymbal crash at the beginning of a drum beat.

i've tried to contain all the sounds on one soundcomplete command eg...

drum.onSoundComplete = function() {

drum.start();
bass.start();
synth.start();

}

which works fine to keep the loops together but now all the volumes are set to zero when i press the button controlling the drum track. i tried to add a variable which was flicked to true onSoundComplete and when the variable was true trigger sounds to all start again. but instead they stopped looping altogether.

cheers,

dave.

[F8] For Loop Conflict - Dynamic Xml Galleries
I'm creating a complex photo gallery system. It's comprised of a nested "for" loop inside another for loop.

The first loop goes through the XML and attaches an MC for each item. If any of these items are photo galleries, then it goes through the second loop to pull out the info for the gallery.

My current code works great if there is one gallery. But as soon as I create more than one gallery, the first gallery stops working and it's next and prev buttons control the second gallery instead.

Here is an abbreviated version of my AS to give you an idea of it:


Code:
var nzog_xml = new XML();
nzog_xml.ignoreWhite = true;
nzog_xml.onLoad = function(success) {
// has XML loaded
if (success) {
var photos = nzog_xml.firstChild.childNodes;
var itemCount = 1;
for (var i = 0; i<photos.length; i++) {
var path = photos[i].attributes.path;
var photoWidth = photos[i].attributes.width;
var photoHeight = photos[i].attributes.height;
var caption = photos[i].attributes.caption;
var imageSet = photos[i].attributes.imageSet;
var photo_mc = _root.center_mc.photosLevel1_mc.attachMovie("photoFrame_mc", "item"+itemCount, itemCount);
photo_mc.empty_mc.loadMovie(path);
// ------------------------------------------------
// is this a gallery and not a single image?
if (imageSet == "true") {
var photoSet = photos[i].childNodes;
var setPath = [];
var setCaption = [];
for (var s = 0; s<photoSet.length; s++) {
setPath[s] = photoSet[s].attributes.path;
setCaption[s] = photoSet[s].attributes.caption;
}
// key listener
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
Key.addListener(listen);
// end key listener
//
// next and prev buttons
photo_mc.setNav_mc.setNavPrev_btn.onRelease = function() {
prevImage();
};
photo_mc.setNav_mc.setNavNext_btn.onRelease = function() {
nextImage();
};
//
p = 0;
total = photoSet.length;
//
nextImage = function () {
if (p<(total-1)) {
p++;
// some actions here
pictureNum();
}
};
prevImage = function () {
if (p>0) {
p--;
// some actions here
pictureNum();
}
};
firstImage = function () {
// some actions here
pictureNum();
};
pictureNum = function () {
photo_mc.setNav_mc.setPhotoNumber_txt._visible = true;
currentPos = p+1;
photo_mc.setNav_mc.setPhotoNumber_txt.text = "image "+currentPos+" of "+total;
};
// start at first image when load
firstImage();

}

// continue original "for" loop here
// . . .
An example of my XML structure would be:


Code:
<photos>
<photo 1 +attributes />
<photo 2 +attributes />
<photo 3 +attributes />
<gallery>
<gallery photo 1 +attributes />
<gallery photo 2 +attributes />
<gallery photo 3 +attributes />
</gallery>
</photos>
My initial thoughts are that I need to somehow give a unique name to each array, variable, and function created inside the nested loop so that they do not override each other. Maybe something like:

Code:
var ["setPath"+itemCount] = [];
instead of just:

Code:
var setPath = [];
Is this correct thinking?

Can someone please advise if renaming all arrays, vars, and functions inside the nested for loop in this manner will solve the problem? And, if so, please give me an example of the correct syntax for this.

Dynamic Image Loop Problem
I am trying to load dynamic images to several movie clip instances using a loop to make things easier. I have two instances on the stage named thumb1 and thumb2 and am loading the images t_01.jpg and t_02.jpg into them as a test. This is my code; however it does not seem to be working. If I target the specific instance, it works, but when I target the instances dynamically using the loop it doesn't work. Thanks for your help. The code also outputs the right instance name in the trace function. What am I doing wrong?


var maxButtons = 2;

for(i=1; i<maxButtons+1; i++){

var thumb = ["thumb"+i];

smoothImageLoad("t_0" + i +".jpg", thumb.container);

trace(thumb + ".container");

}

[F8] Loop And Dynamic Variable Names
Hi,

I got this loop going, which creates button on my stages dynamically. Now I need to create color transforms for each of those buttons while I'm still in the Loop. So I know this doesn't work, but while I'm in the loop I would like to do something like this:


Code:
CountryText_mc.MainButton.onRollOver = function() {
var myOverColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOverColor+[i].setRGB(0x2be237);
}

CountryText_mc.MainButton.onRollOut = function() {
var myOutColor+[i]:Color = new Color(CountryText_mc.MainButton);
myOutColor+[i].setRGB(0xFFFFFF);
}


How can I create those color variables, so that this would work. I need to have myOverColor1, myOverColor2, myOverColor3,... and so on. So I can set them anytime I want.

Thanks for help

[F8] Set Dynamic Links Inside A Loop
I'm drawing Names and IDs from an XML file to create buttons from them. I want to set a get URL action for each button, which is a certain URL + the ID which I draw from the XML.

My problem is that Flash seems to pass the getURL action for every button in the loop but the ID inside the getURL is always the last one that runs in the loop. So getURL always uses the last ID from the XML, no matter which button I click. Here's the code:


Code:
//
define basic variables for setting up the menu
var item_spacing = 25; // how far menu items are spaced veritcally
var item_count = 0; // counts menu items as they are added from the XML


// CreateMenu creates a menu based on the XML object passed.
// It loops through all the items with a for loop adding clips to the menu_mc
// movieclip on the timeline, defining the appropriate text where needed
function CreateMenu(menu_xml){
// start with the first item in the XML
var country = menu_xml.firstChild.childNodes; // menu -> menuitems -> child nodes array

for (var i=0; i<country.length; i++) {

var CountryName = country[i].firstChild;
var CountryId:Number = country[i].firstChild.attributes.id;

var CountryText_mc = menu_mc.attachMovie("MenuItem","Item"+CountryId, item_count);
CountryText_mc._y = item_count * item_spacing;
item_count++;

CountryText_mc.CountryText.text = CountryName.firstChild.nodeValue;

myColor[CountryId] = new Color(menu_mc["Item"+CountryId].MainButton);
myColor[CountryId].setRGB(0x00ffff);

myCountryLink[CountryId] = "/Info/Country.aspx?country="+CountryId;

menu_mc["Item"+CountryId].MainButton.onPress = function() {
getURL(myCountryLink[CountryId]);
}
}
}


// manage XML
// create new XML object instance, remembering to ignore white space
var country_xml = new XML();
//Create an Array to Store and Change Button Colors depending on their CountryID
var myColor:Array = new Array();

var myCountryLink:Array = new Array();

country_xml.ignoreWhite = true;
// define an onLoad to create our location menu when the XML has successfully loaded.
country_xml.onLoad = function(success){
if (success) {
CreateMenu(this);

}

else trace("Error loading XML file"); // no success? trace error (wont be seen on web)
}
// load the xml file!
country_xml.load("Continent.xml");


So the problem is this part:


Code:
myCountryLink[CountryId] = "/Info/Country.aspx?country="+CountryId;

menu_mc["Item"+CountryId].MainButton.onPress = function() {
getURL(myCountryLink[CountryId]);
}


Does someone know how I can write the URL into the getURL as a real string, so it will be the right link for every button? Because this doesn't work. Flash places the CountryId into the getURL at mouseOver and not while creating the buttons. So I got the same link for every button. The rest of the code works fine.

Thank you

Dynamic Text Xml Loop Problem
Am trying to display several records from an XML file into a dynamic text field. The only record that appears in the dynamic text field is the very last record. Am new to AS3 and was wondering what I am doing wrong with the for each loop to get each record. Any help would be appreciated.


PHP Code:



function LoadXML2(e:Event):void {
xmlData2 = new XML(e.target.data);
ParseTitles2(xmlData2);
}

function ParseTitles2(columnsXML2:XML):void {
    
dt_BlogsWriter.styleSheet = cssStyleSheet;

var columnsList2:XMLList = columnsXML2.blog;

for each (var columnsTitle2:XML in columnsList2) {
    
    var headline:String = columnsTitle2.@headline;
    var body:String = columnsTitle2.@body;
    var bw_Date:String = columnsTitle2.@date;

dt_BlogsWriter.htmlText = "<span class='LeadHeadline'>" + headline + "</span><br /><br />" + body + " " + bw_Date + "<br /><br />";

}

blogsWriterScroll.update();
}

[F8] Loop That Defines Variables With Dynamic Name
I'm trying to define a bunch of dynamic text objects on the stage with the same value. As opposed to declaring their value one at a time I would like to do it in a loop. I thought this would be simple, but what I would expect to work doesn't. Below is an example of what I'm trying to do.



Code:
// This Works
textbox0.text = "test";
textbox1.text = "test";
textbox2.text = "test";


// This Doesn't Work
for (var i=0; i<=2 ;i++){
textbox[i].text = "test";
}

Problem On Dynamic Positionning With Xml (on A Loop)
Hello everybody
I have made a map with dynamic positionning dot via XML
but when i load my dots on the map i only have the last node point displayed

My XML

Code:
<carte>
<element texte ="rubrique">
<emplacement definition="...." pos_y="..." pos_x="...." />
<emplacement definition="...." pos_y="..." pos_x="...." />
</element>

<element texte ="rubrique1">
<emplacement definition="...." pos_y="..." pos_x="...." />
<emplacement definition="...." pos_y="..." pos_x="...." />
</element>
</carte>
My script

Code:

function placedot() {i=0;
while (CarteXML.firstChild.childNodes[i] != undefined){nbrTotalL = carteXML.firstChild.childNodes[i].childNodes.length;
for (var j = 0; j<nbrTotalL; j++){duplicateMovieClip(eval("dot" + i), "destMC" + i + j, j);
eval("destMC" + i + j)._x = CarteXML.firstchild.childNodes[i].childNodes[j].attributes.pos_x;
eval("destMC" + i + j)._y= CarteXML.firstchild.childNodes[i].childNodes[j].attributes.pos_y;}
i++;}}

I have tried with a "for" to replace the "while" but with the "for" nothing happen, no dot

Could someone help me please
And sorry for my english
if its not well explained tell me..
thanks in advance

Dynamic Variable Names In A Loop
Hi, I'm still a noob at as3 and I'm trying to write a script so that I can affect variable names using a loop.

For example:


Code:
var varName;

function test(event:MouseEvent):void
{
for (var i = 0; i < 5; i++)
{
varName = "a" + i;
var a[i]:Number = i;
trace ( varName + " = " + a[i]);
}
}
essentially I want it to display like this:

a0 = 0
a1 = 1
a2 = 3
a4 = 4
a5 = 5


So I was wandering if there was syntax for what I'm trying to do.

How To Use AddChild With A Loop And Dynamic Names?
Hey people,

I am trying to use addChild() for hundreds of movie clips by using a loop, but I don't know how to do this in AS3.0.

Right now I have this:

for(var i:Number = 0; i<=100; i++){
var squareClip0:squareClip= new squareClip();
this.addChild(squareClip0);
};

I am trying to do the equivalent of this from AS2.0:

for(var i:Number = 0; i<=100; i++){
duplicateMovieClip("squareClip_mc", "squareClip"+i+"_mc", i);
};

I have the linkage set up already to load it from the library.

I need to create movie clips with an increment in the file name, because I don't want to name all these clips individually.

Any help is greatly appreciated.

How To Loop Automatic Dynamic Slideshow
I am programming a website for a client and I have created a slideshow that dynamically loads images and displays them every 5 seconds. What I am stuck on is a way to loop the slideshow back to the beginning when there are no more images. The amount of images will vary and I do not want to use php or xml to list the images. Please help........

Dynamic Links In Loop Overwriting
I have a navigation script im working on that dynamically creates and spaces movie clip that hold external icons.
the number and spacing and pages they link to are defined by another external xml file.
everything is working great except that all the icons link to whatever url is specified in the last xml node.
It is obvious that the loop is just overwriting the url on each loop, but I cannot as of yet figure out how to write this so it will retain the correct link on each loop. Please take a look and let me know if you have any suggestions.
i have attached the function in which the problem occures.

Thanks in advance









Attach Code

//loop to make icons
function makeIcons (){
for(var i = 0; i < totalIcons; i++){
iconURL = navXML.childNodes[1].childNodes[activeNode].childNodes[i].attributes.icon;
iconLink = navXML.childNodes[1].childNodes[activeNode].childNodes[i].attributes.url;
//create Icon
this.createEmptyMovieClip("icon"+i, this.getNextHighestDepth());
eval("icon"+i).createEmptyMovieClip("container", 99);
//load image
loadMovie(iconURL, eval("icon"+i).container);
//scale and position
setProperty("icon"+i, _xscale, iconPercent);
setProperty("icon"+i, _yscale, iconPercent);
setProperty("icon"+i, _y, yplace);
setProperty("icon"+i, _x, xplace);
//assign link url
//******************************* TROUBLE AREA *********************
eval("icon"+i).onRelease = function() {
getURL(iconLink,_blank);
};
//set reflection
duplicateMovieClip(eval("icon"+i).container, "reflection", 50);
loadMovie(iconURL, eval("icon"+i).reflection);
eval("icon"+i).reflection._alpha = 15;
eval("icon"+i).reflection._rotation = 180;
eval("icon"+i).reflection._x = iconSize;
eval("icon"+i).reflection._y = iconSize*2;

//set position for next icon
xplace = xplace + iconSize + spacing;

}
}

Dynamic Menu With Array And Loop
hi, i am trying to create a dynamic menu. i have used an array for the data and then used a loop to create the menu. i am now trying to add funcionality to the menu so that when a button is released...it will load another movie, etc. also...two of the buttons need to have drop downs...i created those using an array/loop as well but i can't figure out how to have it appear only when the button is rolled over. here is my code so far...any help or recommendations for other tutorials would be appreciated. thanks!









Attach Code

this.attachMovie("bkgrnd", "background", this.getNextHighestDepth());


var xPos = 10;
var yPos = 40;


var menuDepth:Array = new Array();
var metainfo:Array = new Array();
/
metainfo[0] = new Object();
metainfo[0].title = "button1";
metainfo[0].section = "button1";
metainfo[0].view = "button1";
metainfo[0].link = "/button1.html";
metainfo[0].data = new Array();
metainfo[0].data[0] = { title: "subnava", view: "subnava", subview: null, data: null, link:"/subnava.html" };
metainfo[0].data[1] = { title: "subnavb", view: "subnavb", subview: null, data: null, link:"/subnab.html" };
metainfo[0].data[2] = { title: "subnavc", view: "subnavc", subview: null, data: null, link:"/subnavc.html" };

metainfo[1] = new Object();
metainfo[1].title = "button2";
metainfo[1].section = "button2";
metainfo[1].view = "button2";
metainfo[1].link = "/button2.html";
metainfo[1].data = null;

metainfo[2] = new Object();
metainfo[2].title = "button3";
metainfo[2].section = "button3";
metainfo[2].view = "button3";
metainfo[2].link = "/button3.html";
metainfo[2].data = new Array();
metainfo[2].data[0] = { title: "subnava", view: "subnava", subview: null, data: null };

metainfo[3] = new Object();
metainfo[3].title = "button4";
metainfo[3].section = "button4";
metainfo[3].view = "button4";
metainfo[3].link = "/button4.html";
metainfo[3].data = null;


for (i=0; i<metainfo.length; i++) {
attachMovie("container", "nav"+i, menuDepth.push(this), {_x:xPos});
xPos += this["nav"+i]._width - 25;
this["nav"+i].label_txt.text = metainfo[i].title;
this["nav"+i].url_btn._url = metainfo[i].link;
this["nav"+i].view = metainfo[i].view;




if (metainfo[i].data!=null) {
for (j=0; j<metainfo[i].data.length; j++) {
attachMovie("subContainer", "subNav"+j, menuDepth.push(this), {_y:yPos});
yPos += this["subNav"+j]._height;
this["subNav"+j].subLabel_txt.text = metainfo[i].data[j].title;
this["subNav"+j].subUrl_btn._url = metainfo[i].data[j].link;
this["subNav"+j].view = metainfo[i].data[j].view;

}

}




}

Dynamic Loop Event Handler
Hello, I have a loop which dynamically generates the name of 3 textFields: philsText1, philsText2 and philsText3.
How can I also dynamically create 3 different function names in this code:

this["philText"+i].addEventListener(MouseEvent.MOUSE_DOWN, mousedown1);

eg. I want to generate mousedown1, mousedown2 and mousedown3 dynamically.
Is there any way ?

Thanks for any help.

[AS3] Dynamic Create Items With For Loop
Well, i have this line of code

Code:
var t1:thumbBack = addChild(new thumbBack(x, y));
And i want to create many thumbBacks with names t1, t2, t3... with a for loop. Is this possible?

I tried something like this, but it doesnt seem to work

Code:
for(i=0; i<8; i++){
var this["t"+i]:thumbBack = addChild(new thumbBack(10 + i*200 , y));
}
Any other ideas?

[F8] Loading Dynamic Text Using A For Loop
I'm creating a searchable database in Flash where all the content loads dynamically from external sources. the main interface is columns of buttons where clicking in the first column sends the user to a named frame with a second column of buttons, then onto the third column then the final content is loaded into a new movie clip.

The interface uses just one button(a movie clip) and the columns of buttons are created with a duplicateMovieClip function. that part works fine.

However I can't get the button labels to load from an external text file even though I'm using the explicit button names, and I can't get the buttons to react to clicks even though they're "hot", i.e., the cursor changes when I mouse over them. the button behaviors use the dynamic button names.

Here's my code, any suggestions appreciated:


Code:
//creates a load Variables object
loadText = new LoadVars();
loadText.load("text/patent01NumbersText.txt");
//this makes a column of duplicate button movie clips
for (i=0;i<13;i++){
duplicateMovieClip("patentBtn_mc", "patentBtn"+i+"_mc", i);
this["patentBtn"+i+"_mc"]._y = this["patentBtn"+i+"_mc"]._height * i;
};
loadText.onLoad = function(){
patentBtn0_mc.btnLabel_mc.btnLabel_txt.text = this.patentBtn01;
patentBtn1_mc.btnLabel_mc.btnLabel_txt.text = this.patentBtn02;
patentBtn2_mc.btnLabel_mc.btnLabel_txt.text = this.patentBtn03;

};
//this function simply resets all the movieclips to their original up state
//after all mcs have been reset the conditional (if) statement will highlight the appropriate button
function clearAll(){
["patentBtn"+i+"_mc"]gotoAndStop("up");
};
//sets the button frame to go to for up, over and down states
function up(){
this["patentBtn"+i+"_mc"].gotoAndStop("up");
};

function over(){
this["patentBtn"+i+"_mc"].gotoAndStop("over");
};

function active(){
this["patentBtn"+i+"_mc"].gotoAndStop("active");
};
//Should cause the main timeline to advance one frame and stop
["patentBtn"+i+"_mc"]onPress = function():Void {
_root.gotoAndStop(Patent01);
};

this["patentBtn"+i+"_mc"].onRollOver = over;
this["patentBtn"+i+"_mc"].onRollOut = up;
this["patentBtn"+i+"_mc"].onRelease = function(){
gotoAndStop("Patent0"+i);
clearAll();
};

//the if statement that highlights the active button
_root.onEnterFrame = function(){
if (_root.framename == "Patent01") {
this.Menu01_mc.patentBtn01_mc.gotoAndStop("active");
};
};

Dynamic Image Alpha From Loop
Hi,

I have tried a few methods but I'll lead the post with this one. The value for j is tracing properly (100 through 0) but I cannot apply the value to picHolder's alpha property.

If I set picHolder._alpha to a static value, it sets the alpha. But it refuses to take the j value.

Thanks.

CODEfor(var j:Number=100;j>0;j--){
    picHolder._alpha = j;
    trace(j);
}

Actionscript Dynamic Variable Name In Loop
I'm having an issue looping through and accessing variable names dynamically in actionscript.

This code to call one directly works.
CODE    mcSquares.square1.onRollOver = function(): Void {
        mcSquares.square1._visible = false;
    };

Loop Creator ( Dynamic Sound )
Hi everyone,

I'm working on a concept but not sure if it is possible in AS3 Flash Player 9. I have a client requesting - some feedback would be greatly appreciated. I'm looking into building a "loop creator" application.

I basically want to take preset loops and place them on a time track. The loops will be able to layer above each other. I then want to combine the entire track and export as an mp3, is this possible via byteArrays? If so, could I encode the byteArray to MP3 or do I need to use php or something similar.

I'm in the dark on this one. Could definitely use the help.

Anthony
website: sweetiesandgangsters.net
blog: codegasm.blogspot.com

Dynamic Text Not Showing In A For Each Loop...
Hi there,

I'm having a very strange problem. I'm saving in a textfield some text from an xml file but the text does not show at all.

This is my code:

Code:

public function setUpMenu():void {

         /////////// SETUP NAVIGATION BUTTONS         
         menuXML = xml.navigation.children();
         var i:int = 0;
         
         var initY:Number = clogo.y + clogo.height + 30;
         
         for each (var singleMenu in menuXML) {
            
            var menuBtn:MovieClip = new MovieClip();
            var titleString:String = singleMenu.navName.text();
            var widthToSend:Number = 12*(titleString.length);
            var heightToSend:Number = 15;
            var bgmenu:Sprite = new Sprite;
            bgmenu.graphics.beginFill(0xffffff);
            bgmenu.graphics.drawRect(0,0,widthToSend,heightToSend);
            bgmenu.graphics.endFill();            
            bgmenu.alpha = 0;
            
            var navTitleFmt:TextFormat = new TextFormat();
            var navTitle:TextField = new TextField();            
            navTitle.text=titleString;
            navTitleFmt.size=14;
            navTitleFmt.color = 0xdddddd;
            navTitleFmt.font = "Verdana";
            navTitle.width=widthToSend;
            navTitle.height=25;            
            navTitle.embedFonts = true;
            navTitle.wordWrap=true;
            navTitle.autoSize=TextFieldAutoSize.LEFT;
            navTitle.x=2;
            navTitle.y=2;
            navTitle.selectable=false;
            navTitle.mouseEnabled = false;
            navTitle.defaultTextFormat = navTitleFmt;
            navTitle.alpha = 1;
            navTitle.visible = true;
            menuBtn.addChild(bgmenu);
            menuBtn.addChild(navTitle);
            menuBtn.name = titleString;
            menuBtn.buttonMode = true;
            menuBtn.x = 20;
            menuBtn.y = initY + i * (20 + menuBtn.height);
            i++;
            
            menuList.push(menuBtn);
            
            menuBtn.addEventListener(MouseEvent.ROLL_OVER, menuRollover);
            menuBtn.addEventListener(MouseEvent.ROLL_OUT, menuRollout);
            menuBtn.addEventListener(MouseEvent.CLICK, menuClicked);
            menuBtn.alpha = 1;
            addChild(menuBtn);


         }//close For

      }



You'll see from here that for each element in the XMLList I create a mc. I save inside that mc an invisible sprite and the text over it. Pretty standard stuff.

Well, the xml is fine, I traced all, the xml, the xmllist, the 'titleString' var I created, everything is in there. heck even if I change the bgmenu to alpha = 1 it shows! The only thing is that the text is not showing. I traced also "navTitle.text" and is fine.

I change the font to Arial, or any other system font, or even one added to the library and it does not show.

It happens in CS3 and CS4 on a pc, windows vista (just in case it may be a hardware problem).

Any insight? I'm going crazy!

Dynamic Loop With Button Problem
Ok! I'm in need of some help as this is driving me crazy. I have a site with a music control panel. The pannel is basically an on and off button and 4 buttons to chose different songs. I had a few ideas as to how to solve my dynamic problem, but I haven't been able to get them to work.

Using this code allows me to load and loop them dynamically

on (release) {
stopAllSounds();
musicOn = new Sound(_root.musicList);
musicOn.loadSound("song4.mp3", false);
musicOn.setVolume(45);
musicOn.start(.02, 60);
}

I've placed this code on all 4 buttons.
My problem then, is that when I click the button it only initiates the loading of the song to the button, but doesn't play automatically. I have to then click it again in order for it to play. What I would like is to have it play as soon as it is done loading so I (and end user) don't have to click it twice to get it to play.

I also thought of streaming it and that plays it automatically however, it does not allow it to loop. I have also thought about using the onSoundComplete in order to tell it to start over again, but I'm not very versed in a lot of action scripting and cannot figure it out on my own

I would prefer to find a solution where I dont have to stream it and it would just start playing after its done loading (with only one click of the mouse). Only because I believe (and Im not positive on this) that streaming it will ignor my musicOn.start settings of (.02, 60). Obviously it ignors the loop of 60 so why not the .02 as well. At least this is what I think anyway.

Thanks in advance for any help on this!
Chris(Tofer)

Preload Dynamic Images In Loop
Hi all,

Basically I'm loading a few images in seperate MC's through XML.

Here's the code:


Code:

function loadBigPic(num, slides) {
for (i=0; i<slides; i++) {
var imgHold:MovieClip = _root.createEmptyMovieClip("imgHold"+i, _root.getNextHighestDepth());
imgHold.loadMovie(menu[num][1]+i+".jpg");
var temp:MovieClip = _root.createEmptyMovieClip("tmp"+i, 999);
temp.onEnterFrame = function() {
filesize = imgHold.getBytesTotal();
loaded = imgHold.getBytesLoaded();
trace(this);
progres = Math.round(loaded/filesize*100);
_root.preloader._visible = true;
_root.bar._width = (progres*Stage.width)/100;
if (loaded == filesize && filesize>4) {
_root.preloader._visible = false;
delete this.onEnterFrame;
}
};
}
}



When I trace(this) wich you can see in the onenterframe function I only get the last MC. lets say I'm loading 4 images: 0,1,2 and 3. When I trace it only shows _level0.tmp3 . And I see the last image loaded.

Why is it only showing the last one? what am I doing wrong? is there a way to queue up the images for preload?

grtz,

David

How To Load Dynamic Variables Into Array Without For Loop
i have a bunch of variables...

snuggly1="blah";
snuggly2="blah";
snuggly3="blah";
snuggly4="blah";
snuggly5="blah";
snuggly6="blah";

ugly1="goes with blah";
ugly2="goes with blah";
ugly3="goes with blah";
ugly4="goes with blah";
ugly5="goes with blah";
ugly6="goes with blah";

which i acquired via loadvariables.. is there a tidy way to get them into arrays snuggly[0...6] with their assoatated key/values intact?

so i can access them snuggly[1] and ugly[1] so i will know the array's exact length?

i am seeking an ideal alternative to changing my source output to blahs="blah1:::blah2:::" and splitting strings to build the array..

peace, thanks, dross

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