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




Trouble Running A Function In A Function...



this is very odd im running a funsction to check passwords against two lists of passwords...
fist list checks fine, but the sceond list fails even if it is equal...
can somone take a look and tell mewhats wrong?

here is the script for a quick look ive also attached the fla in a zip.


Code:
_root.passwords="1234,4567,test";
_root.adminpasswords="admin,admintest,admin123";

var passes:String = _root.passwords;
var passlist:Array = passes.split(",");


function checkPASS(passlogin) {
trace(passlogin);
for (var i = 0; i<passlist.length; i++) {
trace(passlist[i]);
if (passlist[i] == passlogin) {
trace("in");
gotoAndStop("loggedIN");
break;
} else if (passlist[i] != passlogin) {
trace(failedchecks)
trace(passlist.length)
failedchecks = i;
if (failedchecks+1 == passlist.length) {
trace("second list check");
checkADMIN([passlogin]);
break;
}
}}}


var ADMINpasses:String = _root.adminpasswords;
var ADMINpasslist:Array = ADMINpasses.split(",");


function checkADMIN(ADMINlogin) {
trace("second list checking")
trace(ADMINlogin);

for (var i = 0; i<ADMINpasslist.length; i++) {
trace(ADMINpasslist[i]+" = "+ADMINlogin);

if (ADMINpasslist[i] == ADMINlogin) {
gotoAndStop("loggedIN");
break;

} else if (ADMINpasslist[i] != ADMINlogin) {
trace(failedAchecks)
trace(ADMINpasslist.length)
failedAchecks = i;

if (failedAchecks+1== ADMINpasslist.length) {
trace("second not in");
gotoAndStop("badPASS");
break;
}
}}}



ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 01-09-2006, 02:59 PM


View Complete Forum Thread with Replies

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

Possible To "kill" A Running Function From Another Function?
Hi,


I have two functions. The first has an onEnterFrame = function().


When function #2 is executed, I need it to stop the 1st function from running the onEnterFrame.

Is this possible?

I've tried things like:


functionName.break; and functionName.delete onEnterFrame(); but with no luck.


Thanks for the help!

Function Running
hi, I'm an italian web designer(from Sicily).
I'm can speak little english, sorry
I'm really desperate and iìm risking to be fired , in fact, i have to complete this simulation game about horse-racing within four days.
In this game there are six horses, six Mc running horizzontally inside a Mc named "path"which is almost 3000 pixel long for example.
I have used the random function inn order to simulate the race , but the required mechanism expects the server to decide the arrival chart. I have to make everything "real" ; for example one of th horses might stay back and at a certain point, make up ground and win. I tried to do but i really can't, and i don't know who might be able to help me, i hope ypu will help otherwise..... i don't know what will occur to me
Tahnk you very much

i have a file fla for example:


http://members.xoom.virgilio.it/pepigno75/tryhorse.zip

Why Is Function Running?
Here is what is most probably a dumb question, but my brain has stopped being able to analyze....

Simple function, and then a button that is supposed to call that function.  But the function is being called with out the button being clicked.

What is going on?

CODEmcBox._visible = false;
var btOne:Button

function changeColor(){
    if (mcBox._visible == true){
        mcBox._visible = false;
    }
    else {
        mcBox._visible = true;
    }
}
trace (mcBox._visible);

btOne.onRelease = changeColor();

Stopping A Function From Running
I have a function creating a new clip..


'function makeNewClip(){'


how do i stop the function from running?


//stop button
cow1stop_btn.onRelease=function(){
_root.makeNewClip()=false;
}


basically i want to set makenewclip=null?

Running More Than One Function Simultaneously?
hi i have a need. i have a script on a mc that makes it animate and has functions that tell it where the mouse is, etc.
and i wanted to have several of them, as links on a menu. but it seems like when i test movie, the first one always takes up the whole processor, so that the others functions dont ever even get read. so my question is.. is it possible to run the other functions at the same time? if i "return;" the function that is running, then it wont be detecting the mouse anymore, and thats not really what i want. i want them to all run at the same time. help? ive attached the menu here. the actions are inside menu_mc and then the link_mc's in the actions layer.
thanks!

How Do U Tell A Function To Stop Running?
easy question but i dont know how.

i wanna have this function- fsp ()

be able to run and stop running. how do i do that?

[f8] Running Several Function Simultaneously
Hi, can any show me how to run more than one function at the same time?

I am trying to run this function:

mask.onEnterFrame = function() {
if (this._currentframe == this._totalframes) {
tear_function();
delete this.onEnterFrame;
}
};
function tear_function():Void {
this.onEnterFrame = function() {
if (this.black_dude._x>-70) {
this.black_dude._x -= 12;
}
};
}


for several movie clips, but its only letting me run one at a time. Do i need some kind of loop?

Let me know please!
Thanks.

Function Running Twice At Same Time?
Hello everybody, I am attempting to make a site draw itself with actionscript courtesy of Jim's Flash Bestiary, which can be found here.

Anyway, to the point:

Is there a way to make multiple instances of this function work at the same time? In other words, I want to have multiple "signatures" drawing themselves each time the frame is entered, instead of just one. I tried to do creative things with the script, but I'm at a loss.

The script:

ActionScript Code:
drawSigEF = function()
{
if (getTimer() - this.t >= this.sig[this.i].t*.5)
{
var px = this.sig[this.i];
if (px.m) this.lineTo(px.x, px.y);
else this.moveTo(px.x, px.y);
if (++this.i >= this.sig.length) delete this.onEnterFrame;
}
}

MovieClip.prototype.drawSig = function(sig, thick, clr)
{
this.clear();
this.lineStyle(thick, clr, 100);
this.i = 0;
this.sig = sig;
this.t = getTimer();
this.onEnterFrame = drawSigEF;
}

// Example script usage (using root)
_root.drawSig(sig, 1, 0xFFFFCC);

// Example of a signature, "sig", (the array of
// points etc that makes the signature or drawing.
sig = [
{m:0,x:196,y:47,t:2009},
{m:1,x:192,y:54,t:2042},
{m:0,x:27.4,y:138.7,t:1968},
{m:1,x:26.6,y:137.9,t:2001},
{m:0,x:0.8,y:564.55,t:34033},
{m:1,x:4,y:571,t:34090},
{m:0,x:118.55,y:31.45,t:46580},
{m:1,x:119.35,y:30.65,t:46614},
{m:0,x:12.9,y:15.3,t:3869},
{m:1,x:15.3,y:27.4,t:3902},
{m:0,x:12.9,y:7.25,t:5496},
{m:1,x:14.5,y:12.9,t:5529},
{m:0,x:12.9,y:9.65,t:6288},
{m:1,x:23.35,y:11.3,t:6321},
{m:0,x:13,y:594.95,t:6816},
{m:1,x:18,y:595.95,t:6850},
{m:0,x:13.7,y:4,t:7413},
{m:1,x:9.65,y:5.65,t:7447},
{m:1,x:138,y:576.95,t:1663}
];

I'd also love to learn a more efficient way of doing this, if there is one out there that exists. I just would love to record my drawing on my graphics tablet, have a flash file "replay" the drawing movements, and have that be the layout of the site. Thanks very much everybody,

-Matt O, AS newb.

Running A Random Function
Hey everyone,

I've searched and.. I think I'm just not quite sure what I'm looking at... so here's what I want to do.

I have these three functions, I want flash to pick one and run it when someone loads the page. I want it to pick a random one, either gozilla, bowie, or mj.


// Fun animation 1
function godzilla()
{
menu_mc.godzilla_master._alpha = 100;
godSound.start();
bow = setInterval(function(){rainbow();clearInterval(bow ); }, 200 );
//timer = setInterval(function(){rainbow(); }, 500 );
}

// Fun animation 2
function mj()
{
menu_mc.mj._alpha = 100;
mjSound.start();
mjoff = setInterval(function(){menu_mc.mj._alpha = 0; }, 3000 );
}

// Fun animation 3
function bowie()
{
menu_mc.car._alpha = 100;
getStage();
new Tween(menu_mc.car, '_x', null, sw + 500, -500, 2, true);
bowieSound.start();
}


Right now I have it so when this function finishes

function finishIntro()
{
fade(intro_ring.welcome, 'out', 5);
menuControl();

// This loads a certain animation to surprise the user
god = setInterval(function(){godzilla();clearInterval(go d); }, 5000 );

}

It sets an interval to call the function godzilla. I want basically to use this function finishIntro, and in that last line.. in 5 seconds call either godzilla, mj, or bowie and I want flash to pick.

How do I do this?

Running Js Function In Html From A Swf.
Hi there,

I've got an html page with a swf inside it. Using a click in the swf, I want a javascript function in the head of the html (which has effects in the html) to run.

Hope that makes sense, any help on how to solve this would be wonderful!

Thanks,
Rebecca

Running A Function In A Hittest Once
I have a mc that slides in when the mouse is over it, using a hittest. heres the code:


ActionScript Code:
onClipEvent (load) {
this._x = 670;
vel = 10
}
onClipEvent (enterFrame) {
    if(this.hitTest(_root._xmouse,_root._ymouse,true))
        _root.newy = 412;
    else
        _root.newy = 630;

    fukx += (_root.newy-_x)/vel
    _x = Math.round(fukx);
}

the reason im not using rollOver is that there are other rollOvers within the mc and 2 in one mc conflict.

i want to execute a function when hittest is detected, instead of using the

ActionScript Code:
fukx += (_root.newy-_x)/vel
    _x = Math.round(fukx);
for the movement. so the code would become:


ActionScript Code:
onClipEvent (enterFrame) {
    if(this.hitTest(_root._xmouse,_root._ymouse,true))
        runThisFunction();
    else
        runAnotherFunction();
}

the only problem with this is that the code within the function loops indefinately when used with hittest. How can i tell flash to just run the code within the function once?

Thanks!

Running AFTER A Function's Been Executed?
Below is the current code I'm using. It works fine and does what I need it to do, no problems.

However, I'd previously tried to use a conditional statement to have the last two tweens (3x and 4y) to wait until all the previous ones had finished, and have been unsuccessful and been getting a syntax error for onLoad. I don't know how adding a boolean conditional statement (i.e. dLaunchDone = true) gave me a syntax error for onLoad, but it did. Could be my computer's acting funny, but that's wishful thinking.

I'll be okay if it can't be done, just wondering how I get a function to wait until another has been completely executed before running as well.







Attach Code

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//setting Title to 0 transparency
mcTitle._alpha = 0;

//functions
//slides title down and fades it in
function Launch ():Void
{
//slides title down
var tween1y:Tween = new Tween(this.mcTitle, "_y", Regular.easeOut, this._y, 10, 30, false);
//fades title in
var mcAlpha1:Tween = new Tween(this.mcTitle, "_alpha", Regular.easeOut, 0, 100, 50, false);
//slides blue tab up
var tween2y:Tween = new Tween(this.mcBlueTab, "_Y", Regular.easeOut, 613.0, 135.1, 70, false);
//slides black tab left
var tween1x:Tween = new Tween(this.mcBlackTab, "_x", Regular.easeOut, 551.0, 91.1, 70, false);
//scale the table X
var tween2x:Tween = new Tween(this.mcTable, "_xscale", Regular.easeOut, 0, 100, 70, false);
//scale the table Y
var tween3y:Tween = new Tween(this.mcTable, "_yscale", Regular.easeOut, 0, 100,70, false);
//slide H Grid left
var tween3x:Tween = new Tween(this.mcHGrid, "_x", Regular.easeOut, 629, 90, 70, false);
//slide V Grid down
var tween4y:Tween = new Tween(this.mcVGrid, "_y", Regular.easeOut, -372.1, 134.1, 70, false);
}

//execute on load
onLoad = Launch;

Running A Function From A Child MC?
Hi all
I have a function called menuchange sitting on frame 1 of _root.pt_menu.ptmenumc.menufinal.menuchange

To run this function I would use
_root.pt_menu.ptmenumc.menufinal.menuchange();

Is that correct?

Any help would be great,

Function Not Running In A Class
Hey guys,
I've got a bit of an odd issue. I have a class called UIObject that has a private property called _id. I have a getter/setter for it, and I extend UIObject by a class, lets say, MenuButton. Inside of MenuButton I have this function:


ActionScript Code:
public function create($id:Number):Void    {        this.id    = $id;        trace("=====> create");    }


now, I have a Main class that activates my MenuButtons, and that code is here:


ActionScript Code:
private function initMainMenu():Void    {        for (var i:Number = 0; i < 6; i++)        {            var ob:Object = new Object();            ob.mc = this.menu_mc["item" + i + "_mc"];            ob.mc.create(i);                        ob.mc.onRelease = function():Void            {                trace(this.id);            };        }    }


I've used this code successfully in the past, but for some reason my past two projects, it has not worked and create never gets run. I've tried time and time again to figure out why this isn't working all of a sudden, but I can't. I imagine i'm missing some very small detail and I need someone to point it out to me. Any help is greatly appreciated. Thanks.

- Matt

Running An Object Through A Function
Hiya,
I have some stored info inside object 's'. Everything works when I run s through my function. s is reference to a movieClip which is what actually runs through the function. However, I want to make this action happen by clicking another MC. Look at the code below and it will be easier to see:
Code:
s.onRelease = unReleased;
What I want is to ignite that line of code exactly, but by releasing a different MC, ie:
Code:
exit_mc.onRelease = s.onRelease = unReleased;
However, I dont want to click s to do so. You see, if I call the function unReleased just via exit_mc, then all the stored vars in s aren't put into action, as they aren't running through the unReleased function.
Make sense? I think it's sheer Syntax difficulties on my part.

Help Please! It's simpler than it seems - I know that!

Stop Function From Running
Last edited by permort : 2007-06-29 at 01:40.
























I got this function that I can´t find a way to stop running. I want to stop it and start it later.


ActionScript Code:
var rain = function (raincounter) {
    for (i=1; i<=raincounter; i++) {
        this.attachMovie("rain", "rain"+i, this.getNextHighestDepth());
    }
};
 
rain(100);


Is there any way to break out of this loop from outside the function?
I have also tried to call it again from another place in the flash with:
rain(0);
but it won´t stop "Raining". Can anybody help, please?

Not Running Function Properly.
Right this issue is really bugging me.

I am creating a platform game for which i have created an array function for the enemies. If the character lands on the enemies head then it'll die. However if it walks into it left or right then the character dies via the KidDie() function.

I have tried duplicating this array for Spike. I want to have some spikes so that when the character collides with them he'll die. I have set this up and when the character collides with them then it'll run the KidDie() function.

The KidDie() function is set up so that if the character has no lives then its game over, however if he has any lives left then a message will appear in a dialog, once the ok button is clicked it'll reload the level.

Now, this all works and runs fine when the character collides with the enemy, however, when the character collides with the spikes, regardless of how many lives the character has left it goes straight to Game Over. I've been faffing around for an age trying to fix it but can't seem to figure it out.

I have attached all my code for reference, i have highlighted the relevant sections of code...

Code:

       ///////////////////////////////////////   
     // RELEVANT CODE IS BELOW THIS POINT //
   /////////////////////////////////////
      
      
      // check collisions with enemies, items
      public function checkCollisions() {
         
         //enemies
         for(var i:int=enemies.length-1;i>=0;i--) {
            if (kid.mc.hitTestObject(enemies[i].mc)) {
               
               // is the kid jumping down onto the enemy?
               if (kid.inAir && (kid.dy > 0)) {
                  enemyDie(i);
                  playSound(theVirusDie);
               } else {
                  kidDie();
                  playSound(theFall);
               }
            }
            
         
         
         // spikes
         for(var s:int=spikes.length-1;s>=0;s--) {
            if (kid.mc.hitTestObject(spikes[s].mc)) {
                  kidDie();[/color]
               
            }
      }
         }         
            
         
         
         //items
         for(i=otherObjects.length-1;i>=0;i--) {
            if (kid.mc.hitTestObject(otherObjects[i])) {
               getObject(i);
            }
         }
      }
      
      
      
      // remove enemy
      public function enemyDie(enemyNum:int) {
         var pb:PointBurst = new PointBurst(gamelevel,"Virus Removed",enemies[enemyNum].mc.x,enemies[enemyNum].mc.y-20);
         gamelevel.removeChild(enemies[enemyNum].mc);
         enemies.splice(enemyNum,1);
      }
      
      //enemy got player
      public function kidDie() {
         // show dialog box
         var dialog:Dialog = new Dialog();
         dialog.x = 375;
         dialog.y = 250;
         addChild(dialog);
      
         if (playerLives == 0) {
            gameMode = "gameover";
            dialog.message.text = ".:: Game Over ::.";
            
            
         } else {
            gameMode = "dead";
            dialog.message.text = "Infected by Virus";
            playerLives--;
            
         }
         
         kid.mc.gotoAndPlay("die");
         playSound(theFall);
      }
      
      
      // player collides with objects
      public function getObject(objectNum:int) {
         // award points for treasure
         if (otherObjects[objectNum] is Binary1) {
            var pb:PointBurst = new PointBurst(gamelevel,100,otherObjects[objectNum].x,otherObjects[objectNum].y);
            playSound(theBinarySound);
            gamelevel.removeChild(otherObjects[objectNum]);
            otherObjects.splice(objectNum,1);
            addScore(100);
            
            
         } else if (otherObjects[objectNum] is Binary0) {
            pb = new PointBurst(gamelevel,500,otherObjects[objectNum].x,otherObjects[objectNum].y);
            gamelevel.removeChild(otherObjects[objectNum]);
            playSound(theBinarySound);
            otherObjects.splice(objectNum,1);
            addScore(500);
            
         } else if (otherObjects[objectNum] is heart) {
            pb = new PointBurst(gamelevel,"Extra Life",otherObjects[objectNum].x,otherObjects[objectNum].y);
            gamelevel.removeChild(otherObjects[objectNum]);
            playSound(theNewLife);
            otherObjects.splice(objectNum,1);
            playerLives++;
            livesDisplay.text = String(playerLives);         
      
            
            
            
         // got the key, add to inventory
         } else if (otherObjects[objectNum] is Key) {
            pb = new PointBurst(gamelevel,"Password Obtained" ,otherObjects[objectNum].x,otherObjects[objectNum].y);
            playerObjects.push("Key");
            playSound(theBigBinary);
            gamelevel.removeChild(otherObjects[objectNum]);
            otherObjects.splice(objectNum,1);
            
      // got the key, add to inventory
         } else if (otherObjects[objectNum] is KeyTwo) {
            pb = new PointBurst(gamelevel,"Password Obtained" ,otherObjects[objectNum].x,otherObjects[objectNum].y);
            playerObjects.push("KeyTwo");
            playSound(theBigBinary);
            gamelevel.removeChild(otherObjects[objectNum]);
            otherObjects.splice(objectNum,1);
            
            } else if (otherObjects[objectNum] is Laptop2) {
            if (playerObjects.indexOf("KeyTwo") == -1) return;
            if (otherObjects[objectNum].currentFrame == 1) {
               otherObjects[objectNum].gotoAndPlay("open");
               playSound(theComplete);
               levelComplete();
               
            }
            
         // hit the door, end level if hero has the key
         } else if (otherObjects[objectNum] is Laptop) {
            if (playerObjects.indexOf("Key") == -1) return;
            if (otherObjects[objectNum].currentFrame == 1) {
               otherObjects[objectNum].gotoAndPlay("open");
               playSound(theComplete);
               levelComplete();
               
               
         
               
            }
            
         // got the chest, game won
         } else if (otherObjects[objectNum] is Chest) {
            otherObjects[objectNum].gotoAndStop("open");
            gameComplete();
         }
               
      }
      
      // add points to score
      public function addScore(numPoints:int) {
         gameScore += numPoints;
         scoreDisplay.text = String(gameScore);
         livesDisplay.text = String(playerLives);         
      }
      
      
      
      // update player lives
      public function showLives() {
         livesDisplay.text = String(playerLives);
      
      }
      
      
      
   public function showClock(event:Event) {
         //milliseconds passed
         var timePassed:int = getTimer()-startTime;
         
         //computer minutes and seconds
         var seconds:int = Math.floor(timePassed/1000);
         var minutes:int = Math.floor(seconds/60);
         seconds -= minutes*60;
         
         //convert clock to string
         var timeString:String = minutes+":"+String(seconds+100).substr(1,2);
         
         //show in text field
         timeDisplay.text = timeString;
         
      }
      
      
      // level over, bring up dialog
      public function levelComplete() {
         gameMode = "done";
         var dialog:Dialog = new Dialog();
         dialog.x = 375;
         dialog.y = 250;
         addChild(dialog);
         dialog.message.text = "Stage Passed";
         dialog.time.text = "Time Taken : "+timeDisplay.text+"
";
         
      }
      
      
      // game over, bring up dialog
      public function gameComplete() {
         gameMode = "GAME OVER";
         var dialog:Dialog = new Dialog();
         dialog.x = 375;
         dialog.y = 250;
         addChild(dialog);
         dialog.message.text = "You Got the Treasure!";
      }
      
      // dialog button clicked
      public function clickDialogButton(event:MouseEvent) {
         removeChild(MovieClip(event.currentTarget.parent));
         
         // new life, restart, or go to next level
         if (gameMode == "dead") {
            // reset kid
            showLives();
            kid.mc.x = kid.startx;
            kid.mc.y = kid.starty;
            gameMode = "play";
         } else if (gameMode == "gameover") {
            cleanUp();
            gotoAndStop("start");
         } else if (gameMode == "done") {
            cleanUp();
            nextFrame();
         }
         
         // give stage back the keyboard focus
         stage.focus = stage;
      }         
      
      
      public function playSound(soundObject:Object) {
         var channel:SoundChannel = soundObject.play(0);
      }
      
      // clean up game
      public function cleanUp() {
         removeChild(gamelevel);
         this.removeEventListener(Event.ENTER_FRAME,gameLoop);
         stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
         stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
      
      }
      
      }
}


As you can see i have set the spikes up in a loop within the checkCollisions() function.

The relevant code is just under half way under the heading // RELEVANT CODE IS BELOW THIS POINT //.

I by no means expect anyone to read through all the code but i thought it would help to post it all. I have highlights the two functions of note.

Any help whatsoever would be welcome. Its really bugging me as everything works fine and debugs correctly but it just goes straight to gameover even if the character has lives.

Thanks again

Kindest Regards

Tom

Having Problems With AttachMovie Function While Running
Hi,
I'm trying to make flash read values from a text file and draw some graph out of them but I want it to do it step by step. If I make it draw it all at once there is no problem, but it doesn't seem to be working when I try to make it attachMovie during the animation. I'd like to create a loop by wich it would read two values of an array of 2 numbers inside a much larger array and assign this variables to de _x and _y coordinate. Do I have to change something from the linkeage of the symbol?

Thanks a lot.

Function Running Automatically On Swf Load
I have some actionscript:


Code:
this.menuSelect.b3.dynTextHolder.dynText.text = "OTHER";
this.menuSelect.b3.dynTextHolder.onRelease = Vidd("other");

function Vidd(whichVideo) {
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoHolder.theVideo.attachVideo(ns);
ns.play("tm"+whichVideo+".flv");
trace ("function exec also "+whichVideo);

}


ok, now when the flash movie loads, the trace in the function is automatically run when the flash clip loads, and doesn't execute again. Even when I click on b3. It's quite simple code, I can't figure out why it isnt running only when b3 is released.

b3 is a button with an .AS file attached to it so that the object knows how to animate when I drag out an instance. Would that make a difference?

Thanks!

Running A Function Upon Song Completion
I'm working on a project that plays random song tracks. Right now it just randomly plays a track and then stops. Is there any way for Flash to start the next song after one song completes.

Here is the script I have so far. BTW, a couple people on this forum helped me with this. They were a HUGE help with helping me understand how this works.


Code:
var songs:Array = new Array("music/track0.mp3", "music/track1.mp3", "music/track2.mp3", "music/track3.mp3", "music/track4.mp3", "music/track5.mp3", "music/track6.mp3", "music/track7.mp3", "music/track8.mp3", "music/track9.mp3", "music/track10.mp3", "music/track11.mp3");
var songPlayed:Array = new Array();
function randomSong() {
var randomNumber = random(songs.length);
var notinList = true;
for (i=0; i<songPlayed.length; i++) {
if (songPlayed[i] == randomNumber) {
notinList = false;
}
}
if (notinList) {
songPlayed.push(randomNumber);
playSong(randomNumber);
} else if (songPlayed.length == songs.length) {
songPlayed = new Array();
randomSong();
} else {
randomSong();
}
}
function playSong(randomNumber) {
track = new Sound();
track.loadSound(songs[randomNumber], true);
track.onSoundComplete = function() {
randomSong();
if (_root.soundOff_mc._currentframe=2) {
track.setVolume(0);
}
};
}
randomSong();

Running Function Of A Loaded Movie
Hello all,
I've got a parent movie that's loading external swf's into 7 container movieclips using the loadMovie() function. That's all good. I need to, however, have external images loaded into additional container movieclips INSIDE those swf's upon them being completely loaded into the parent movie. I know how to reference a movieclip loaded into a level, but if you're loading an swf into a container movieclip, how do you attribute an instance name to it for later referencing? It seems to me that loadMovie() doesn't have this quality.

Insight?

Running Function In External As. Files
Hello, I have two external as. files.

this function is in Photo.as

ActionScript Code:
function getTagsAsStrings():Array
    {
        var returnTags:Array = [];
        for(var id:String in _tags) {
            var t:Tag = _tags[id].tag;
            returnTags.push(t.value);
        }
        return returnTags;
    }

and I wish to run it in this .as file and have the results put into an array of variables..


ActionScript Code:
import com.kelvinluck.util.LogWrapper;
import com.kelvinluck.flashr.core.FlashrResponse;
import com.dynamicflash.utils.Delegate;
import com.kelvinluck.flashr.core.ResultsSet;
import com.kelvinluck.flashr.core.Photo;
import com.kelvinluck.flashr.core.Flashr;
//import com.kelvinluck.flashr.core.Tag;

class com.kelvinluck.flashr.example.FlashrSimpleSearch extends MovieClip
{
   
    public static var NUM_RESULTS:Number = 1;

   
    private var _flashr:Flashr;
    private var _flashrResponse:FlashrResponse;
    private var _searchio:Photo;
   
    private var _numResults:Number;
    private var _photos:Array;
   
   
    // these fields are just for debugging
    var out:TextField;
    var scrollDown:Button;
    var scrollUp:Button;
   
    /**
    * Function: FlashrSimpleSearch
    * Constructor
    **/
    function FlashrSimpleSearch()
    {
        // uncomment the following lines if you want to see the internals of what is happening with Flashr.
        LogWrapper.getInstance().init();
        LogWrapper.getInstance().addTracePublisher();
        //LogWrapper.getLog().setLevel(Level.ERROR);
       
        _photos = [];
       
        _flashr = Flashr.getFlashr();
        _flashr.apiKey = "b40e05adf210ad4c4cc4da00f99f4184";
        _flashr.cacheQueries = true;
       
       
        _flashrResponse = new FlashrResponse();
        _flashrResponse.onPhotosSearch = Delegate.create(this, onPhotosSearch);
        _flashrResponse.onPhotosGetInfo = Delegate.create(this, onPhotosGetInfo);
       
       
       
        // initialise our debugging scroll buttons
        scrollDown.onRelease = Delegate.create(this, onScrollDown);
        scrollUp.onRelease = Delegate.create(this, onScrollUp);
    }
   
    function doSearch(tags:String)
    {
        log("Searching for " + NUM_RESULTS + " photos matching tag '" + tags + "'");
        _flashr.photosSearch({tags:tags, per_page:NUM_RESULTS});
    }
   
    function onPhotosSearch(rs:ResultsSet)
    {
        _numResults = rs.photos.length;
        log("Loading " + _numResults + " photos out of possible " + rs.total + "");
        for (var i:Number=0; i<_numResults; i++) {
            var thisPhoto:Photo = rs.photos[i];
            _flashr.photosGetInfo(thisPhoto.id, thisPhoto.secret);
           
            //easypeasy = _searchio.getTagsAsStrings(thisPhoto);
            //trace (easypeasy);
        }
    }
    function onPhotosGetInfo(photo:Photo)
    {
        _photos.push(photo);
        if (_photos.length == _numResults) {
            onAllPhotosLoaded();
        }
    }
    function onAllPhotosLoaded()
    {
        for (var i:Number=0; i<_photos.length; i++)
        {
            // put all the photos into a variable each loop
            var thisPhoto:Photo = _photos[i];
            // y co-ord
            var nY:Number=110;
            // x co-ord
            var nX:Number;
            // stolen from some old code, basically setting the spacing between each picture, it increases the
            //spacing as the loop increments
            nX = 25 + (_photos.length * 10) + (i * 78);
            // create a movieclip to load the photos into
            var mc:MovieClip = _root.createEmptyMovieClip("photo"+i, i);
            mc.createEmptyMovieClip("img", 1);
            // and load the image into it
            mc.img.loadMovie(thisPhoto.thumbnailUrl);   
            mc.photo = thisPhoto;
   
           
           
                           
            // position the images using our co-ords
            mc._x = nX;
            mc._y = nY;
           
            // open photo page when photo clicked
            mc.onPress = function()
            {
                getURL(this["photo"].photoPageUrl, "_blank");
            };
           
        }
    }
   
    // the following functions are just used for the textfield we are tracing into...
    function log(m:String)
    {
        trace(m);
        out.text += m + newline;
        out.scroll = out.maxscroll;
    }
    function onScrollDown()
    {
        out.scroll += 1;
    }
    function onScrollUp()
    {
        out.scroll -= 1;
    }
   
    /**
    * Function: toString
    **/
    public function toString():String
    {
        return "[com.kelvinluck.flashr.example.FlashrSimpleSearch]";
    }
}

im not too sure how to do it,


any help would be greatly appreciated! you guys were a great help last night!

Update Of Display While Function Is Running
I have a function where I run the following code:


ActionScript Code:
// Update database
    admin_status.text = "Here we go - lets get started with "+  arr_sql.length +" queries!";
    var db = new database();
    for (var i = 0; i < arr_sql.length; i++) {
        db.query(arr_sql[i]);
trace(i +"/"+ arr_sql.length +" completed...");
        admin_status.text = i +"/"+ arr_sql.length +" completed...";
        if (i >= 200) {
            break;
        }
    }
    admin_status.text = "Database updated.";

It runs many SQL queries and then for each query I want to update a TextField that I have named admin_status. So I set the text property for each loop but the only thing I ever see is "Database updated" when it's all done (but I see the traces). Why is that? Is the display only updated after a function has finished?

I guess I have to make asynchronous database queries instead?

Allan

FPS Speed Problem When Running A Function
Hello All,


I have encountered something very strange in my programming. I have a many functions in this program I'm creating. one I will concentrate on.

My program is loading in external files (SWF's) into a holder in another movieclip (well deep). - The loading is fine, work flawlessly.

Next, after all of these SWF's have loaded into thier repective MovieClips, I run another function and delete the one that called it.

This is fine...still working.

This function aligns all the movieclips just loaded into Columns and rows. Here is where my problem begins. I have done this code many a time before, and have seen no problems, I'm running at 32 FPS, and it always seems to screw up the alignment in some way, it does work sometimes, but not all the time (which is what I need)

My question is, then, should the speed (FPS) of the movie actually affect how the code works? If I drop the FPS down to 12, it the screwups happens less often, and if I drop down to 5 FPS it works fine...but the loading takes a while and makes things really choppy (as I woudl expect from a lower FPS).

Does anyone have a solution to this? or an idea on why the FPS affects what the code is doing?

Baffled.

Running A Function In A Parent At The End Of A Child.swf
question: How do I call a function that is inside a parent.swf from a child external swf (class Loader)?


In my menu.swf, there is a child (Loader class) of a content.swf that gets loaded below it on run. Then when a button is clicked, it makes a string that contains the name of the content file to load next, then initiates an ending function on the child, which does some outro animation.

function buttonClick(event:MouseEvent):void
{
nextContent = event.target.name + ".swf";
MovieClip(newContent.contentLoaderInfo.content).endSequence();
}

------------------------------------------

after the ending sequence has executed in the ccontent.swf I need to know how to make a call to a function back in the menu.swf so that I can load the nextContent

Running A Function Multiple Times
I have posted this question in several different ways and looked all over, but I still don"t know...

I have a function that creates an object(I've run into this problem while creating movieclips and sounds) I only want one of this object to exist. So when the function is called again I want it to remove the previous object. Does that make sense, I don;t know if this is a coding question or if I need to understand something about how the compiler works or what, but any advise or links would be appreciated.

Possible To Disable Key Input While Running Function?
Building a FlashLite 1.1 app for my phone and just wondering if anyone has been successful with this? I'd like to temporarily disable the phone's keypad while the the script is processing the input it just got.

i.e. You press a key. It stops listening to the keyboard while it calculates the results. It displays the results and starts listening again for input.

Cheers!

Running A Function From An Imported Class
Code:

class class1 {
   public var mc:MovieClip;
   public function configUI() {
      setX();
      setY();
   }
   private function setX() {
      mc._x = 10;
   }
   private function setY() {
      mc._y = 10;
   }
}




Code:

import class1;

class class2 extends MovieClip {

   private function onLoad():Void {
      configUI();
   }
}


the interfaceInitiate class returns an error:
There is no method with the name 'configUI'

Can anyone tell me why this might be happening[/code]

[F8] Running A Function When Rolling Over An Attached Movieclip
Ok

What i am trying to get done is when i rollover a attached movieclip, code runs.

My code is below, i bolded what I thought would work, but its not, nothing comes up in the output box

Thanks alot


//begin to make navigation for user to use
_root.createEmptyMovieClip("navContainer", this.getNextHighestDepth());


//fill navContainer with the navigation images
for(var i =0; i<totalNodes;i++)
{

var clipSeparator =35;
navContainer.attachMovie("navImageClip","nav"+i , i , {_x:i* clipSeparator,_y:0});


navContainer["nav"+i].loadMovie(rootNode[i].attributes.thumbnailLocation);


navContainer["nav"+i].onRollOver = function ()
{
trace(this._name);

};


}

SetInterval-called Function Keeps Running; ClearInterval No Help
I have spent ALL DAY trying to figure out what is going wrong here.

I have an empty movie clip which loads a movie clip (a photo border)
from the library, that movie clip in turn loads an external image.

I wrote actionscript which rotates the empty movie clip + movie clip +
external image in from the right edge of the compiled .swf. Then I want it to pause for a few seconds, then rotate out off the right edge, then rotate back in with a new external image.

What happens is the first image loads, it rotates in as expected,
pauses, then rotates out of view. The second image loads, rotates in,
then immediately rotates out. It does not pause.

I figured out that clearInterval was not actually clearing the
interval, so the rotate out function keeps running. I actually had to
alter the rotate out function's 'if' statement, because what it had
been doing previously is rotating out the first movie clip, then the
second movie clip would just sit there at the edge stuttering because
there was a conditional statement telling it to rotate in, while the
setInterval function was still running and telling it to rotate out.
Can someone please PLEASE tell me what is going wrong here?


Code:
onClipEvent (load) {
var randomNum:Number = Math.random();
var stopValue:Number = Math.round((randomNum * 35) - 18);
_rotation = -179;
var rotateUp:Boolean = false;
var ind:Number = 0;
var loaded:Boolean = false;
}
onClipEvent (enterFrame) {
if (_rotation == -179 && rotateUp == false && loaded == false) {
clearInterval(ID);
if (ind != 5) {
ind++;
}
else {
ind = 1;
}
var MC:String = 'pic'+String(ind)+'MC';
attachMovie(MC,MC,10,{_x:120,_y:90});
loaded = true;
trace ('MC is '+MC);
}
if (rotateUp == false) {
trace('rotateUp is '+rotateUp);
_rotation+=1;
trace(_rotation);
if (_x < -95) {
_x += 0.5;
}
if (_rotation >= stopValue) {
rotateUp = true;
}
}
if (rotateUp == true) {
rewind = function() {
clearInterval(ID);
if (_rotation > -179 && rotateUp == true) {
_rotation -= 1;
if (_x >= -200) {
_x -= 0.75;
}
}
}
ID = setInterval(rewind,5000);
if (_rotation == -179) {
clearInterval(ID);
rotateUp = false;
removeMovieClip(MC);
loaded = false;
randomNum = Math.random();
stopValue = Math.round((randomNum * 35) - 18);
}
}
}
as you can see, I've stuck clearInterval() just about everywhere
because it seems like that's the problem... the interval is not
getting cleared, so the function called by setInterval just keeps
running.


Code:
if (_rotation > -179 && rotateUp == true)
this is the 'if' conditional where I added an additional condition to prevent the above- referenced stuttering. But this still is not giving me the pause that I want before the movie clip rotates out again.

Thanks in advance.

Quick Function Running Order Question
Hi there,

Justa quickie to check tht my understanding on functins and how they are called is correct.. For my high score board i have two functions..

AddScore() and ShowScores()

On Frame 3 of my mc i want to add the players score and thn show all the high scores with this new value.. If i call the function from the timeline as such:

AddScore('Anthony','12');
ShowScores();

Will flash process all of addscore() before starting ShowScores() or does the speed of the program interfere with this order.. If so how can i make sure that AddScore() has completed before ShowScore() runs

Hope this makes sense

Ant

Running A Function On A Dynamically Generated Field
Hello,
I'm having trouble with some dynamically generated textareas. They have external content that needs to be formatted as it goes in. I'm trying to get a function to run that will do this but no matter where I put it it doesn't want to work.
Your help would be most appreciated.
Thank you,
Beatie







Attach Code

//Text area format function to suck out extra spaces
var contentLoader:LoadVars = new LoadVars();
contentLoader.onData = function(content:String) {
if (content != undefined) {
_global.introTextArea.text = content.split("
").join("
");
_global.Instr1TextArea.text = content.split("
").join("
");
_global.Instr2TextArea.text = content.split("
").join("
");
_global.Instr3TextArea.text = content.split("
").join("
");
_global.Instr4TextArea.text = content.split("
").join("
");
_global.Trig1TextArea.text = content.split("
").join("
");
_global.Trig2TextArea.text = content.split("
").join("
");
_global.Trig3TextArea.text = content.split("
").join("
");
_global.Trig4TextArea.text = content.split("
").join("
");
_global.Act1TextArea.text = content.split("
").join("
");
_global.Act2TextArea.text = content.split("
").join("
");
_global.Act3TextArea.text = content.split("
").join("
");
_global.Act4TextArea.text = content.split("
").join("
");
}
};
//run the function
contentLoader.load("content/introduction.xml", "content/instructions01.xml", "content/instructions02.xml", "content/instructions03.xml", "content/instructions04.xml", "content/trigger01.xml", "content/trigger02.xml", "content/trigger03.xml", "content/trigger04.xml", "content/activity01.xml", "content/activity02.xml", "content/activity03.xml", "content/activity04.xml");

Running Function Call Stored As String
I have a variable that contains a function call as a string but Im having trouble running it. It may sound a bit strang but I need it done this way for reasons to long and boring to go into.


ActionScript Code:
function MyFunction(Param){
trace(Param)
}
StoredFunctionCall = "MyFunction(1)"


How would I run MyFunction(1) by using the StoredFunctionCall string

Could really do with some help
Thanks

Stop Running The Rest Of This Event Listener/function
How do get the rest of the code in a Event listener to stop running...

ActionScript Code:
function yesClick(event:MouseEvent):void {
    currentMC.visible=false;
    if (event.target.parent.name=="step_1_mc") {
        if ((check_1_On) ||(check_2_On) ||(check_3_On)) {
            trace(check_1_On);
            step_1_mc.error_mc.visible = false;
            step_2_mc.visible=true;
            currentMC = step_2_mc;
        } else {
            step_1_mc.error_mc.visible = true;
            // after the above else statement has run
                // I want yesClick to stop running
        }
thingsIDontwantToRun1.x = 45;
thingsIDontwantToRun2.y = 700;
}

[MX04] SetInterval Function Running Finite Number Of Times...
Hi,

I was wondering if someone could look over this(see code below). It basically stops responding and offers to stop running the script.

What I'm trying to do is run a function a finite number of times with an interval between each time it runs.

There may be a better way of doing it otherwise but any suggestions would be brill, Ta.

Neily


PHP Code:



onClipEvent (mouseUp) {
    var Counter=0;
    
    do {
        setInterval(TraceTest,1000);
    } while (Counter<=10);

    setInterval(TraceTest,1000);
    
    function TraceTest(){
        trace("Function Called" + Counter);
        Counter++;
    }
}

TROUBLE With Function
i put a function on the main Timelime :

function SectionIs (xxx) {
section = xxx;
trace ("i goto 2 " add section);
loadMovie (section add ".swf", 3);
}

and i call it with these insctruction

on (press,release) {
_root.SectionIs("flexibility");
}

if i call it from the main Timelime, it work, but when i call it from a MC, nothing happen ? ! §

what's wrong ? ? ?

Function Trouble Again...
The following code doesn't work...I believe it explaines itself.


Code:
function rollup() {
if (_root.news_mc._currentframe = 19) {
movie = news_mc
} else if (_root.partners_mc._currentframe = 19) {
movie = partners_mc
} else if (_root.artists_mc._currentframe = 19) {
movie = artists_mc
} else if (_root.about_mc._currentframe = 19) {
movie = about_mc
} else if (_root.portfolio_mc._currentframe = 19) {
movie = portfolio_mc
}

_root.movie.text_mc.play();
_root.movie.empty_clip.mask.reverse = true;


trace ("Film = "+(movie));
}
The trace always give news_mc even when I'm 100% sure that only ie. artists_mc is in frame 19
I have tried some similar ways of writing it but can't get it to work. Theres probably a smarter way of doing this.

Thanks

Function Trouble
I have a function called Blood();, it's supposed to make blood appear where an enemy just died, so here's the function.
the perimiter Object calls for the instance name of the MC it's on

function blood(object) {
i++;
duplicateMovieClip("_root.blood", "blood"+i, i;
_root["blood"+_root.i]._x=_root.object._x;
_root["blood"+_root.i]._y=_root._object._x;
}

My problem is that when it duplicates it doesn't duplicate in the same spot as the enemy and I need to know how to make it duplicate under it.

Function Trouble.
Hi,

I just started with flash and action script 2 days ago (I'm accustomed to other languages though, C, php, javascript ).
Anyways I'm making a simple flash movie where the user can add objects to their house by pressing a button and they can submit what they created to a php script.

That part of the script works, however I also want a button so the user can remove an object which have been placed, I'm using this code to do that;









Attach Code

_root.amtrocks++; // How many objects the user is allowed to place.
removeObject( this );
this.removeMovieClip();

function removeObject( pphy ):Void
{
trace( "hello" )
for( i = 0; i < 100 && i < _root.objcount; i++ )
{
if( object[i].obj == pphy )
object[i].placed = 0;
}
}


amtrocks gets incremented and the movie clip gets deleted,
but it doesn't seem like the removeObject() function even gets executed, seeing as the "hello" trace never appears.

Why is this?


To create the objects I use the following code;

on(press)
{
if( amtrocks >= 1 )
{
duplicateMovieClip( _root.rock, "phyobj"+placedc, placedc );

setProperty ("phyobj"+placedc, _x, 0);
setProperty ("phyobj"+placedc, _y, 0);

setObject( 1, "phyobj"+placedc );

placedc++;
amtrocks--;
}
}

function setObject( typ, pphy ):Void
{
for( i = 0; i < 100 && i < _root.objcount; i++ )
{
if( object[i].type == typ && object[i].placed == 0 )
{
object[i].placed = 1;
object[i].obj = pphy;
break;
}
}
}

Apologies for the noob question.

























Edited: 04/29/2007 at 05:40:42 AM by Waterbottle2

Trouble Using The SetInterval Function
I am trying to load in external swf files into a target movie clip randomly after a set period of time, but i am having trouble creating the code following the example from the sctionscript dictionary.

Can anyone help me??!!

I need the code to be in MX

HELP!

Trouble With Button Function
hi I have a button instance on the stage on frame 20, called stop_btn. A movie clip instance named video_mc.

I am trying to write a function for the button, on frame 1 of my functions layer on the main time line. ( basically so i can keep all my button code in one place)

the function is

// stop video clip button
stop_btn.onRelease = function() {
video_mc.stop;
};

both the button and the movie clip are also on the main timeline.

I cannot get this to work, I have a similar function using getURL for another button which works perfectly, however this one does nothing.

does anyone have any ideas,
Thanks in advance
Mark

Trouble With Function Scope?
do functions have a scope?
i can call a function when its in the same clip
but if i declare it outside of the clip i want to use it in
it doesn't work!
aren't functions global...that is ..cant i declare and call from anywhere
i'm very frustrated..help please

Trouble Calling A Function
if in one movieclip i define a function, how would i call that function from within another movieclip?

[F8] Trouble With 'LoadMovie' Function
Hi, I'm using the LoadMovie function so that when a button is pressed it loads a mini-game .swf file into a movie clip called 'holder'
I am using this code on the button:


Code:
on(release){
function() {
holder.unloadMovie();
holder.loadMovie("Http://mygameaddresshere.swf");
}
}
It's not reporting any errors but it's not loading the .swf either. I've checked the url I'm directing it to and that works.

Do I need to set the posisiton, width and height of the .swf file? I figured it would work off the center point of the movieclip but maybe not?

Any help is much appreciated thanks!
-Olly

[F8] Trouble With Mc Stop Function?
i am building a banner for a friend and i am trying to make it that when you rollover the mc, it will go to frame 120 and play through 179. the problem is i can't get it to stop at frame 179 until i rollout.
can anyone help me with this, i'm sure its something simple.
here is my code.

on (rollOver) {
_root.gotoAndPlay(120,179);

// i think i'm missing some kind off stop function here//
}
on (rollOut) {
_root.gotoAndPlay("go1");


}
on (release) {
getURL("http://www.website.com", "", "POST");
}

any help would be great, thank you.

MC Button Function Trouble
Hello,

I am interested in adding a function for an MC so that upon rolling off the MC, the navigation on the main timeline moves forward 1 frame. Here's what I've got on the main timeline for an MC w/instance name "upLeft":

upLeft.onRollOut = function(){
gotoAndPlay(2);}

What happens though is the navigation moves to frame 2 regardless of the user's interaction with the MC. Do I need an action on the MC also? Or is my function incomplete?

I've attached a small .fla for perusal.

Thanks in advance,

llyfre

Trouble Using The Same Function For More Than 1 Button...
Hello all,

I am trying to create a menu and what I want to do is have several instances of button use the same function. This should be easy, but I am having a problem understanding AS3

Here is my code...


ActionScript Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;

btn_1_mc.addEventListener(MouseEvent.MOUSE_OVER, animIn);
btn_1_mc.addEventListener(MouseEvent.MOUSE_OUT, animOut);
btn_2_mc.addEventListener(MouseEvent.MOUSE_OVER, animIn);
btn_2_mc.addEventListener(MouseEvent.MOUSE_OUT, animOut);
btn_3_mc.addEventListener(MouseEvent.MOUSE_OVER, animIn);
btn_3_mc.addEventListener(MouseEvent.MOUSE_OUT, animOut);


function animIn(event:MouseEvent):void
{
     new Tween(this,"y",Regular.easeIn,0,-10,.25,true);
}
function animOut(event:MouseEvent):void
{
    new Tween(this,"y",Regular.easeOut,-10,0,.25,true);
}
btn_1_mc.buttonMode = true;
btn_2_mc.buttonMode = true;
btn_3_mc.buttonMode = true;

Any ideas to make this work?

Trouble Calling A Function
Hey there,

Whenever I call a function on the timeline of another mc it's no problem. But when I call this function when it is inside a duplicated movieclip I get no result.
The function spawnMe() is called a n number of times. That works well. But the goToWork() function inside the duplicated mc does'nt respond at all.

ActionScript Code:
function spawnMe() {
    duplicateMovieClip("blob", "blob"+m, m);
    this["blob"+m]._x = random(800)-200;
    this["blob"+m]._y = random(800)-200;
    this["blob"+m].goToWork();
}
This one is on the timeline inside the duplicated mc:

ActionScript Code:
function goToWork() {
    trace("working");
}

Can someone help me out here? Thanks

Trouble With UnloadMovie(); Function
the below content was my original problem...but now i found out whats wrong! look go here http://cutshallow.com/swf/photostest.html and go to the photos section...while your there look at the galleries...i made a test xml file with one gallery with one blank image...another gallery with three blank images and one images and then a third gallery with four blank images and one image...now take a look at what happens when you press on the third image and then the second...that one picture is still there...which means the images aren't being deleted as they should...even though at the beginning of my functions in the code i have it unload the movies...so does anyone have any ideas as to why this is happening? and how i can fix it?

--------------------------------------------------

alright well i created this image gallery using xml...and well, thought it works...there are a few flaws that i can't seem to fix...before i try to explain the problem, though, i will explain the way my gallery works...
in the library i have four exported movie clips:
imageMC(linkage id: "imageMC): a movie clip with two movie clips inside...one blank movie clip("image") and one movie clip with a box graphic ("box_mc")
galleryMC(linkage id: "galleryMC"): a movie clip with 2 movie clips inside, blank movie clip("image") and a text button("view"), and two dynamic text fields("title" and "caption");
txtButton(linkage id:txtButton): a movie clip with a dynamic text field inside("text")
titleCaption(linkage id:titleCaption): a movie clip with two dynamic text fields inside("title" and "caption")
on the stage i have two empty movie clips:
images_mc and galleries_mc
and here is my actionscript:

ActionScript Code:
loadGalleries();var galleries = [];var images = [];var m:Number;function loadGalleries() {images_mc.unloadMovie();gXML = new XML();gXML.ignoreWhite = true;gXML.load("xml/photos.xml");gXML.onLoad = function(success) {if (success) {parseXML(gXML);}function parseXML(xmlDoc) {for (i in xmlDoc.firstChild.childNodes) {file = xmlDoc.firstChild.childNodes[i].attributes.file;title = xmlDoc.firstChild.childNodes[i].attributes.title;caption = xmlDoc.firstChild.childNodes[i].attributes.caption;galleries[i] = [];galleries[i] = [file, title, caption, i];}}for (i in galleries) {var k:MovieClip = galleries_mc.attachMovie("galleryMC", "gallery"+i+"_mc", galleries_mc.getNextHighestDepth(), {_y:i*70});file = galleries[i][0];title = galleries[i][1];caption = galleries[i][2];id= galleries[i][3];k.title.htmlText = "<b><u>"+title+"</u></b>";k.caption.text = "- "+caption;k.image.loadMovie(file);k.image._xscale = k.image._yscale=13;k.id= id;with (k) {view.onRelease = function() {_parent._parent.loadImages(id);};}}};}function loadImages(number) {galleries_mc.unloadMovie();iXML = new XML();iXML.ignoreWhite = true;iXML.load("xml/photos.xml");iXML.onLoad = function(success) {if (success) {parseXML(iXML);}function parseXML(xmlDoc) {for (i in xmlDoc.firstChild.childNodes[number].childNodes) {file = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.file;title = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.title;caption = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.caption;images[i] = [];images[i] = [file, title, caption];}}c = images.length;for (i in images) {var p:MovieClip = images_mc.attachMovie("imageMC", "image"+i+"_mc", images_mc.getNextHighestDepth());p._x = i*55;if (p._x>3*55) {p._y += 45;p._x -= 4*55;if (p._x>3*70) {p._y += 45;p._x -= 4*55;}if (p._x>3*70) {p._y += 45;p._x -= 4*55;}}file = images[i][0];title = images[i][1];caption = images[i][2];p.image.loadMovie(file);p.image._xscale = p.image._yscale=p.box_mc._xscale=p.box_mc._yscale=10;p.url = file;p.title = title;p.caption = caption;with (p) {box_mc.onRollOver = function() {_parent.titleCaption.title.htmlText = "<b><u>"+title+"</u></b>";_parent.titleCaption.caption.text = "- "+caption;};box_mc.onRollOut = function() {_parent.titleCaption.title.htmlText = "";_parent.titleCaption.caption.text = "";};box_mc.onRelease = function() {getURL("javascript:newWindow('"+url+"','','530','400','scrollbars=no','resize=no');");};}}var l:MovieClip = images_mc.attachMovie("titleCaption", "titleCaption", images_mc.getNextHighestDepth(), {_y:(c/4)*60, _x:130});var t:MovieClip = images_mc.attachMovie("txtButton", "goBack", images_mc.getNextHighestDepth(), {_y:(c/4)*70+20});t.text.text = "<< back to galleries";t.onRelease = function() {loadGalleries();};};}

now to explain what i have happening here...there are two main functions in the movie...the first one to be called is the loadGalleries(); function...
and in that function i load the xml file "xml/photos.xml":

HTML Code:
<photos>
<gallery file="../photos/uploads/cssicck500.jpg" title="Awesomenessssssss" caption="we're cooler than you">
<image file="../photos/uploads/51716042_l.jpg" title="Hawaii" caption="hawaiians are so hawaiian" />
<image file="../photos/uploads/51801565_l.jpg" title="Wide-eyed wes" caption="what the..." />
<image file="../photos/uploads/142391447_l.jpg" title="Mr. moves" caption="so flamboyant" />
<image file="../photos/uploads/142391784_l.jpg" title="Rockin' danny" caption="wild and crazy is he" />
<image file="../photos/uploads/142392907_l.jpg" title="Cut Shallow on tour" caption="not anymore" />
<image file="../photos/uploads/142394266_l.jpg" title="The whole gang" caption="the only good one of nate...and you can still barely see him" />
<image file="../photos/uploads/csmyspace.jpg" title="Good day sir..." caption="I SAID GOOD DAY!!" />
<image file="../photos/uploads/cssicck500.jpg" title="Epitome of awesome" caption="you heard me, shoot" />
</gallery>
<gallery file="../photos/uploads/cssicck500.jpg" title="Test" caption="this gallery is just a test" images="9">
<image file="../photos/uploads/51716042_l.jpg" title="Hawaii" caption="hawaiians are so hawaiian" />
<image file="../photos/uploads/51801565_l.jpg" title="Wide-eyed wes" caption="what the..." />
<image file="../photos/uploads/142391447_l.jpg" title="Mr. moves" caption="so flamboyant" />
</gallery>
</photos>
and for each gallery item in the xml code...it defines the "gallery" array...each item in the array is one gallery...and inside that item is all the information for that gallery...here is what the array now looks like after this loop:
gallery[["../photos/uploads/cssicck500.jpg", "Awesomenessssssss", "we're cooler than you", 0]["../photos/uploads/cssicck500.jpg", "Test", "this gallery is just a test", 1]]
so now...it attaches the gallery for every item in the gallery array and gives it the correct information for each gallery...(file, title, caption, and id);
and then it defines an onRelease = function for the "view" text button inside the gallery item... and inside this function it calles on the next main function in the movie "loadImages(number)" which in this case is loadImages(id);
so in the case that i pressed the first gallery item..id would be 0 and therefore "number" would be 0 which would make the next peice of code:

ActionScript Code:
function parseXML(xmlDoc) {for (i in xmlDoc.firstChild.childNodes[number].childNodes) {file = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.file;title = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.title;caption = xmlDoc.firstChild.childNodes[number].childNodes[i].attributes.caption;images[i] = [];images[i] = [file, title, caption];}}

be the following:

ActionScript Code:
function parseXML(xmlDoc) {for (i in xmlDoc.firstChild.childNodes[0].childNodes) {file = xmlDoc.firstChild.childNodes[0].childNodes[i].attributes.file;title = xmlDoc.firstChild.childNodes[0].childNodes[i].attributes.title;caption = xmlDoc.firstChild.childNodes[0].childNodes[i].attributes.caption;images[i] = [];images[i] = [file, title, caption];}}

but the problem is...it doesn't do this correctly...for example...right now in the xml code i have two galleries...one have 8 images and the otehr has three...if you press on the gallery that has 3 images first..it'll display three images like it should...and you go back...everything still working good...you press on the other gallery...it displays 8 images like it should...still all going good...but when you go back after pressing that gallery is where the problem starts....now no matter which gallery you press, it always displays the gallery with 8 images...and it always seems to do this...sticking with the gallery that has the most images in it...any idea as to why its doing this?

(oh and by the way...there are a few other flaws in the script like for instance, i can't find any way to make it so that flash automatically detects when a new row of images needs to be started, so when i need a new row, i need to tell flash myself when to start a new row...so thats a flaw, and also the size of the images is a problem...when i make the thumbnails its always gonna scale the images down to 10% of the original size...which means if i upload a small image the thumbnail size will be extremely small...and there are a few others i can't think of...so can someone please help me?)

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