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




GotoAndPlay Function



Ok, I do very little actionscript writing, I'm trying to make a simple flash webpage with cool animation and I'm using scenes to seperate the different pages.

It's pretty simple, main page is Scene 1, next page off that is Scene 2, etc, etc. To keep things simple, I put each individual animation in it's own movie symbol so I can reuse it at any time. This includes an animation where the main navigation buttons pop in and out.

Alright, I set 2 scenes so far, each with using different symbols, etc. In the first scene, I set one of the buttons to call frame 1 of scene 2 using the following code:
on (release) {
gotoAndPlay("Scene 2", 1);
}

Unfortunately, the buttons have their own local timeline and when I click the button, It just reloads the button animation from frame 1. I need to make it so it calls scene 2 of the root timeline.

Thanks



FlashKit > Flash Help > Flash ActionScript
Posted on: 05-07-2006, 06:23 PM


View Complete Forum Thread with Replies

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

GotoAndPlay Function
Hello. I'm trying to use the gotoAndPlay function.

At the main timeline, I use labels like, music, weblinks, etc to indicate which frame starts what.

In one the symbols's timeline, I've added some twain movements. I need to link back to the main timeline.

Have tried using
on (release) {
gotoAndPlay ("Scene 1", "music");
}

but everytime I click the link, it goes back to my main page. (the first page)

If I try
on (release) {
gotoAndPlay ("Scene 1", 110);
}

110 is the frame number to where music label is shown.
It WORKS!

*puzzled* Did I do something wrong? I really would like to use labels, as I'm sure I will move the frames and I am afraid I'll forget to change the frame number later.

help help

p/s: if my explanation above is not clear, do let me know.

GotoAndPlay Function
Hi all,

i need some help please with the gotoAndPlay() function.

Here is how the flash appears:

Once the .swf file is loaded, a movieclip plays (embedded in the timeline) and there are 3 boxes to choose from. Hovering each box, plays another movie clip (embedded in the timeline) as well

I want to have a link when you enter box1 and box2 to take you directly to the contents of box3. (in the library is named as "page3")

In the source file, there is already a "back" button and i duplicated it and insert it inside BOX1, named as "page" in the library. The link works but takes you back to the beginning of the movie clip when the 3 boxes appear.

Is there a way to make the link take you in the "page3" which is defined as movie clip, directly? The "page3" appears under "Scene 1" and it has its own set of layers

Thanks in advance

Foundas

GotoAndPlay From A Function
I've got a function named addQuarter which has gotoAndPlay("Add Play") inside of it. The gotoAndPlay sits inside a for loop and 2 if statements in the function. The actionscript on the "Add Play" frame adds some text to a text box and loops itself until no more text needs to be added. That all works great, until I want to call my function two times in a row. For example...


Code:
addQuarter(1);
addQuarter(2);
The output of this will be something like the following...
1st Quarter - Created by addQuarter(1);
2nd Quarter - Created by addQuarter(2);
1st and 10, HOME 40 - Created by the gotoAndPlay call of addQuarter(2);

The problem with this is the gotoAndPlay call of addQuarter(1) isn't allowed to run, it just gets overridden by the gotoAndPlay call of addQuarter(2). What I need to happen is addQuarter(1) runs, the gotoAndPlay finishes, and THEN addQuarter(2) starts.

I've done some tracing inside my function and i've found that the gotoAndPlay call runs simultaneously with the rest of the function. So if i had gotoAndPlay("Add Play");
trace("Inside Function");

The trace would be executed while "Add Play" is still adding its content to the text box. I've tried changing my "Add Play" actionscript to a function and just calling it with a parameter, but this just generates all the content at once rather than adding it into the text box one line at a time. I appreciate any advice/help you guys can give me. Thanks.

Gotoandplay Function
Hi, i've generated an invisible button within a movie on the last keyframe of the stage which has a gotoandplay action within it.

This takes the user to keyframe 1, currently the action only works on the last keyframe after the stop action (where the button is placed)

Is there a way to get this action to work on all frames at anytime in the movie without adding the gotoandplay button on each keyframe.

Probably very simple but i'm having trouble finding a solution.

Cheers in advance

Gotoandplay Function
Is there a gotoandplay function in actionscript 3? I can't seem to find it. I would like to use a frame label instead of a frame number if possible. I would also like to play the flash movie backwards to a certain point when the user clicks a certain button. I have seen it done before in Actionscript 2, but do not know how in actionscript 3.

The GotoAndPlay Function
Been doing flash for a while but some of it still bothers me. I am using the gotoAndPlay function from inside movie clip instance. I do _root.gotoAndPlay("game",5) but it still goes to the intro scene's clip five, is there anyway to call specific scenes from inside clips?

Function With Gotoandplay Label?
I have a setInterval function and it seems to work with frame numbers but not frame labels..

This script is not really working as what I'd like it do. I want it stop 3 seconds and then go to the next or another label


wait = function (waittime){
gotoAndPlay('tolocation'); //tolocation is supposed to be a frame label variable, not sure if I should use single quote??
clearInterval(myTimer); //stops the function being called again
}
myTimer = setInterval(waittime, 2000); //calls the function wait after 2 sec

Then I use the below to idenitfy the label name and call the function, I used:

tolocation = "testlabel"
wait();

Can someone kindly please help or point out whats wrong???

thanks so much!!

[F8] How Do Use A String In A GotoAndPlay Function?
Hi.

Ok this may be a simple question to answer, but I'd be dammed if I can get it to work! On the main scene I have a stop command where it pauses for a button to be pushed. When the button is pushed I want it to continue down the timeline. When it gets to the end of the timeline it will jump scene to the scene corresponding to the button that they pushed earlier.

Here's what I have so far... On the first frame I have declared a variable...


Code:
var videoplay_string;


Then when it's paused for the button push...


Code:
this.southport_mc.southport_btn.onRelease = function() {
videoplay = "southport_central";
gotoAndPlay("continue");

};


(where "continue" is a marker on the main timeline) and then finally at the end of the timeline...


Code:
gotoAndPlay("videoplay", 1)


Can anyone help? Thanks

GotoAndPlay In Function Problem
function troubles
i want to do

function hit(rubriek) {
_root.onpage=0;
_root.titel=rubriek;
showtitle();
}
function showtitle(){
_root.titel.gotoAndPlay("in");
}

but it won't work...

showtitle(); works on it's own, but not when called in hit("test");
other actions in hit function do work... only no gotoandPlay or gotoandStop actions...

any ideas?

GotoAndplay Like Function For Scenes?
I am trying to make a tour and I am doing things in scenes. How would I do something so I can use a button to go to different scenes and start playing it?

GotoAndPlay Function.....help Needed
Hi,

I am trying to make a televison that when a combination of numbers are pressed, and enter is pushed, it will go to a specific scene depending on what numbers were pushed.

Here is the script i have so far

Code:
Button_Enter.onPress = function()
{
scene = "Website_" + channel.text;
gotoAndPlay("scene", 0);



}
That is the script for the Enter button.

Website_ is the name of the scene + channel.text which is the number

For example, when i punch in 8 and press enter, it takes me to the next slide which is Website_1, insead of Website_8.

Any help would be greatly apreciated.

Problems With The GotoAndPlay-function
Hello Im about making my first website in flash. I have animated the
interface now, but suddenly it seams like the
Code:
gotoAndPlay();
doesn`t work anymore. It makes the frame which is intended, but it want
play from there unless I use a
Code:
play();
in the frame.

I made a new scene with a simple tween to test from scratch but the same problem goes there.
I have attached this tween so you can try it out. If the file works fine for you perhaps the program has to be broken or some sort!?! I uninstalled and installed again but the same problem was here

NavigateToUrl + GotoAndPlay In One Function?
I would like my button to cause the browser to load an external swf at a specific frame (not the first frame). navigateToURL works great to load the external swf, but it doesn't appear to allow me to gotoandPlay a specific frame. I thought that perhaps another way to get the external swf to go to its specific frame might be to put some AS in the first frame of the external swf that looks for a referrer and jumps to a frame based on where the user has come from (based on referrer). But I know no AS3 other than what I've gleaned from these forums and Flash CS3 Help files. I see nothing about referrers. Any ideas?

Varibale Passing To GotoAndPlay() Function
Hey Everyone. Happy Holidays.

I'm trying to pass a variable from the _root of my movie to a gotoAndPlay() function on a movie clip.

This variable is set on the root:
which = '"b_wh"';


Here's the code when I'm trying to access the variable:
onClipEvent(enterFrame){
this.gotoAndStop(_root.which);
}

Inside this clip, I made a fake dynamic text box to see if the variable was being passed correctly. It shows up in this text box, but it doesn't send the movieclip to the right frame. Any ideas????

Disable Button With GotoAndPlay Function?
Hello all. I've got a quick question about disabling buttons.
My scenario:
I have button one (instance name btn1) that when clicked will gotoAndPlay the FrameLabel "begin" in the movieclip called "MC". Now, I need the same button that was just clicked to gotoAndPlay "begin" to instead gotoAndPlay the FrameLabel in the same movieclip, "off".
I realize this is very confusing, i was honestly getting lost while i was typing it for you all. So let me just breakdown bluntly what i'm trying to achieve.

I need a main button that, when first clicked, opens an animated menu that the user can then select other buttons within the menu to navigate the site, then once the main button is clicked once more with the menu visible, the menu then animates away.

I give you my utmost apologies if my entire post is too vague. I've been hacking away at this problem with every solution i deem possible, but i'm sure there is an easier way. ANY help, and or ideas, is excellent. Take care.
Victor.

Urgent, How To Add Gotoandplay Command To A Function...
I've got this countdown function for my game, it's a timer of 100 seconds. I want to add a command so when the 100 seconds are up, it will GOTOANDPLAY scene 'GAME OVER' frame 1...

havent got a clue how to do that, here's my function....


cheers for the help guys



howLong=100;
max = bar._x;
min = max - bar._width;
total = max-min; bar._x = max;

//initialize the text display
display_txt.text=howLong;

start_btn.onPress=function(){countDown()}

function countDown(){
var totalTime = howLong*1000;
var startTime = getTimer();
this.onEnterFrame=function(){
percent = (getTimer()-startTime)/totalTime;
bar._x = max-(percent*total); display_txt.text=Math.floor(howLong+1-(howLong*percent));

if (percent>1) {
this.onEnterFrame=null;
s=new Sound();
s.attachSound("smack");
s.start();
_parent[functionName]();
}
}
}


cheers guys!!!

Error 1006: GotoAndPlay Is Not A Function
ActionScript Code:
var categorias:Array = [accesorios,acero,apoyamaletas,blanqueria,cestos,cortinas,espejos,
                        iluminacion,manijon,minibar,muebles,secadores];

for(var i=0;i<categorias.length;i++){
    categorias[i].addEventListener(MouseEvent.MOUSE_OVER,mouseIn);
    categorias[i].addEventListener(MouseEvent.MOUSE_OUT,mouseout);
}

//categorias.gotoAndPlay('blurIn');

var inicio:Array = categorias;
var mostrarID = setInterval(mostrar,50);

function mostrar(){
    if(inicio.length>0){
        var mc = inicio.splice(Math.floor((Math.random()*inicio.length)),1);
        trace(mc)
        mc.gotoAndPlay('blurIn');
    } else {
        clearInterval(mostrarID);
    }
}

categorias is an Array of MovieClips.
Everything works fine except for the gotoAndPlay() inside mostrar().

trace(mc) returns objects (the ones inside categorias, which are placed in the scene and work fine with the events set before).

Commented categorias.gotoAndPlay('blurIn'); works just fine when uncommented

What is going on?

Many Thanks

Passing Function Parameter To GotoAndPlay()
Hi,

I am currently stuck trying to get pages witin a site to goto and stop on certain frames using a function.

I am attempting to go to a frame within the movie clip "pageContent". Then from there enter another movie clip in this instace the clip is called "extranetContent" and go to and stop the labelled frame "two".

Here is the function and below that is the code I am using to call it. I have used various combinations of string and literal to try to get this to work but have still had no success.

function callContentPage(page, pageNumber){
trace(page + pageNumber);
pageContent.gotoAndStop(page);
pageContent[page]+Content.gotoAndStop(pageNumber);

}

I am using the following code to call the function:

_root.callContentPage("extranet", "two");


Any help would be much appreciated, as I have tried a similar thing before and had no luck, but it seems like it should be so simple to do.

Thanks.

Dabush.

Simple Combobox Issue With GotoAndPlay Function
I'm quite new to Flash and was put onto a job that requires simple Flash use.
I've visited several forums but none are as simple as my problem. I am currently making a overview tutorial on our software, and I simply want to have a combobox that skips to the frame I choose.

I have put the data as the names of sections within the software I want to skip to, but I am willing to change them to whatever makes the creation of the combobox easier weather its frame numbers or whatever.

And as a side helper I am trying to change the highlight color to something other than the default light green and dark green selection.

Any help is appreciated thx.

Is GotoAndPlay A Problematic Function Jumping To New Scenes?
I am creating a flash piece with multiple scenes. When I jump using the gotoAndPlay function, it jumps to the scene but the playhead stays at frame 1 instead of playing on from frame 1 of the new scene. I have been using gotoAndPlay jumping to labelled frames often with little problems. But not to scenes. Is there some problem with using gotoAndPlay function to jump to new scenes?

TIA

Question About GotoAndPlay Function Within A Movie Clip...
I've got a seperate SWF movie that is loaded within my main movie

loadMovieNum ("menu.swf", 9);

And I want to have a 'back' button within that seperate SWF that goes back to the start of my movie.

Anyway, when I try creating a button with this code:

on (release) {
_root.gotoAndPlay(6);
}

It doesn't work.

Can anybody tell me why?

Cheers.

Is GotoAndPlay A Problematic Function Jumping To New Scenes?
I am creating a flash piece with multiple scenes. When I jump using the gotoAndPlay function, it jumps to the scene but the playhead stays at frame 1 instead of playing on from frame 1 of the new scene. I have been using gotoAndPlay jumping to labelled frames often with little problems. But not to scenes. Is there some problem with using gotoAndPlay function to jump to new scenes?

TIA

Question About GotoAndPlay Function Within A Movie Clip...
I've got a seperate SWF movie that is loaded within my main movie

loadMovieNum ("menu.swf", 9);

And I want to have a 'back' button within that seperate SWF that goes back to the start of my movie.

Anyway, when I try creating a button with this code:

on (release) {
_root.gotoAndPlay(6);
}

It doesn't work.

Can anybody tell me why?

Cheers.

Quick Question About GotoAndPlay Function Within A Movie Clip...
I've got a seperate SWF movie that is loaded within my main movie

loadMovieNum ("menu.swf", 9);

And I want to have a 'back' button within that seperate SWF that goes back to the start of my movie.

Anyway, when I try creating a button with this code:

on (release) {
_root.gotoAndPlay(6);
}

It doesn't work.

Can anybody tell me why?

Cheers.

How To Call GotoAndPlay Function Activated In _root From An External MC With AS3?
Dear all,

I am newbie in AS3. I have a problem:

parent movieclip:
var ldr:Loader = new Loader();
ldr.mask = rect;
var url:String = "yes/color_match.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);

--> the external MC is color_match.swf


Problem is: how can I call _root to gotoAndPlay(frame) in the child (which is color_match)?
I tried and prompt error: color_match.as, Line 87
1061: Call to a possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObjectContainer.

Anyone can help me? It takes me quite lots of time for this stupid code.

Thanks,
michoux

GotoAndPlay("label") Function
Hi,
I am new to flash and I hope somebody can help me on this.

I have a main flash file (A.swf). In the first frame I use the load Movie function to load a second swf file (B.swf) in a movieclip called contents

_root.contents.loadMovie("B.swf"); (OK so far)

the A.swf file contains a button.

On release of this button I would like to goAndPlay starting from a frame in the B.swf., this frame is labeled "music".

I tryed this code
on (release) {
_root.contents.gotoAndPlay("music")
}
but it does not work.

How can I do?
Thanks

GotoAndPlay This...then...gotoAndPlay That? (transition Animations For Menus)
Hi all,

Quick question. How do I make my nav buttons trigger an animation that removes the main menu graphics(in an animated way) then loads up the graphics for the relevent section thats been selected?

All I can do is have the buttons click straight to the frame label with the relevent pages on them. I need to have an 'ending animation' for the main page to see first before continuing on.

Thanks for any help.

"gotoandplay" Function
im setting up a flash webpage and i want one of my movieclips to play after another has finished. i placed a "gotoandplay" method at the end of the movieclip that plays first. is this the correct process? any suggestions?

"gotoandplay" Function
im setting up a flash webpage and i want one of my movieclips to play after another has finished. i placed a "gotoandplay" method at the end of the movieclip that plays first. is this the correct process? any suggestions?

GotoAndPlay Works, But Now This.gotoAndPlay?
I want to but my navigation in the library. Then when a certain button gets clicked, I want to go to a certain scene.

So I have the action

on (Release)
{
_root.gotoAndPlay ("Scene 3", 1);
}

for the button in the library. This does not work. If I put this in Scene 1 on the first frame, it also doesn't work. Putting

gotoAndPlay ("Scene 3", 1);

there works.

So my question is: How do I change between scenes from a library button?

[MX04] GotoAndPlay Then GotoAndPlay
Newbie here... how would you do this...

if (_currentframe=="concept_stop" or _currentframe=="develop_stop" or _currentframe=="gallery_stop") {
gotoAndPlay(_currentframe + 1) THEN gotoAndPlay("develop_start");
} else {
gotoAndPlay("develop_start");

Basically, I want it to play the frame after the current frame until it stops, then play the develop start frame... how would you do that?

Function In A Function In A Function, A Scope Problem
Is this basic or what.. I have a nested functions, and I'm having a hell of a time getting all my variable through.

ActionScript Code:
var canyouseemee;
public function move()
   {
      for(var i:Number = 0; i < blah; i++)
      {
         zing, and then zang
         if (zing==0)
         {
             guts
         }
         if (zang ==0)
         {
             something else
         }
      }
   }

Now, I had always thought that since var canyouseemee is declared at the topmost layer, that I'd be able to see it from anywhere below it. Well, it turns out that I can only see it from within the move()function, and not anything below it. is this normal? I thought you couldn't see a local variable of a lower (deeper) function, but could see higher (shallower) variables...

Call A Function In A Duplicated Movie Clip Form Another Function : (
i have a movie clip on my root name "pl".
on command, it duplicates with instance name as "y0","y1", etc.

here is the method :

function callPL(transmit,receive,addy,level) {

var newName = "y"+_root.x;
duplicateMovieClip("_root.pl",newName,101);
_root[newName]._x = 400;
_root[newName]._y = 400;

_root.[newName].start(transmit,receive,addy,level); //look here
}


there i attempt to call a function of the newly duplicated clip call "start()".
Start() function is written on the first frame of the movieclip like this :


function start(a,b,address,level) {
a.sendAndLoad(address,b,"Post");

this.path = b;

b.onLoad=function(success) {
gotoAndPlay("start");
}
}


however it seems like the function callPL() could not invoke function start() of the new movieClip.I have no idea how is it so.
Even when i trigger it with a onLoad handler it still doesnt work
pls shed some light.

Calling Constructor In Condition: A Function Call On A Non-function Was Attempted.
Hi guys,

Please help me somebody with this cos I have really no idea. I have made a simply condition calling a constructor of a class. Today I had to add an "else if", what caused the compilator to show me "A function call on a non-function was attempted."...

ActionScript Code:
function loadIt() {    if (var1 == "1") {        var a:SomeClass = new SomeClass(true);    } else if(var2 == "1"){         var a:SomeClass = new SomeClass(false); //<- if this is not here, everything works fine    } else {        var b:SomeOtherClass = new SomeOtherClass();        b.init();    }}

Any ideas? Thanks for any help!

Poco

Filling Function Arguments With Array Items, Function.call()
HI!

I have this code but I cannot work out how to fill in function parameters based on an array and it's length, see line 7

ActionScript Code:
import com.robertpenner.easing.Cubic;MovieClip.prototype.framesTimeout = function(func:Function, frames:Number, args:Array) {    var t:Number = 0;    var mc:MovieClip = this.createEmptyMovieClip(String(new Date().getTime()), this.getNextHighestDepth());    mc.onEnterFrame = function() {        if (t == frames) {            func.call(this._parent,args);            delete this.onEnterFrame;            this.removeMovieClip();        } else {            t++;        }    };};MovieClip.prototype.movex = function(x:Number, frames:Number) {    trace(x+" "+frames)    delete this.movex.onEnterFrame;    this.movex.removeMovieClip();    if (!frames) {        frames = 20;    }    var t:Number = 0;    var sx:Number = this._x;    var ax:Number = x-this._x;    var mc:MovieClip = this.createEmptyMovieClip("movex", this.getNextHighestDepth());    mc.onEnterFrame = function() {        if (t == frames) {            delete this.onEnterFrame;            this.removeMovieClip();        } else {            t++;            this._parent._x = Cubic.easeOut(t, sx, ax, frames);        }    };};MovieClip.prototype.otherfunction = function(param1, param2, param3, param4){    trace(param1+" "+param2+" "+param3+" "+param4)}mc.framesTimeout(movex, 50, [100, 50]) mc.framesTimeout(otherfunction, 200, ["asd", 1, 2, 55])

Is it possible to call a function and fill in the parameters based on an array and it's lenth?

My Function Isn't Functioning/Actionscript To Call A Function Flash MX 2004
Hello,

Well in theory I know how to create a function but for some reason I am unable to call it.

Can someone take a look at it and tell me what went wrong. Basically when I go to "a certain page" I want to click on a button and have it go to another page known as "pics" it then will load a jpeg there known as jpeg loader. Now I know it works properly without a functin, but because I am lazy I do not want to write more code than I have to, there are like 300 differnt jpegs I have to load. Thus I need to create a function.

here is my AS


ActionScript Code:
//this is on frame one of my root timeline
//I am trying to call the function "display" on release of my button
 
omnihotelButton.onRelease = display ("J010 Omni Hotel.jpg");
 
 
//this is my function that I set up it is also on my root, but on a different frame
//this function is named display and it goes to the "pics" page and stops
where it then loads a jpeg which is et up as my variable.
//the xscale and the yscale are just setting up my size of the jpeg.
 
function display(jpeg){
    _root.gotoAndStop("pics");
    jpegLoad_mc.loadMovie(jpeg);
    jpegLoad_mc._xscale=90;
    jpegLoad_mc._yscale=90;
}

Function Calling From The _root But Call A Function Within A Instance
I have created a new instance 'Check_1' to work as a checkbox with a set of propertys and functions.

All ive done is created the functions in a script in the first frame of the instance-movie these are...

Simple......
================================================== =======

selected = -1;
function select_frame (FrameNum) {
gotoAndPlay (FrameNum);
}
function change_select () {
select_frame(2);
trace (selected);
}
function change_unselect () {
select_frame(1);
selected = -1;
}

================================================== =======

now from the _root i wish to call the above functions to change the instance propertys, it all works fine from within the instance but i also need to use the functions for that instance from the _root...

iv'e tried the follow with no joy...


_level0.Check_1.change_select()


Any light would be greatly appreciated.

Parsing Data To A Function And Altering It Inside The Function
Hi all

I need to parse variables to a function and let the values of the variables be changed inside the function. But in a way that the data are actually changed, not only a reference to the data! It is not possible using primitive data but should be possible with composite data.
But I cant get it right - any suggestions?

code:
test = new Object();
test = false;

aFunction = function(control){
control = true;
trace(test);
other code here...
}


How can I make the trace(test) output true when I call the aFunction(test) with test as parameter?

Hope anyone have the answer!

Ciao ciao

T

Define The OnMouseDown Function To Point To A Member Function
Hi,

I have a class called CField that contains a MovieClip. And I like to be able to call a member function inside my class, when the mouse click on the MovieClip. If I use the callback function onMouseDown = function() from inside the class, the function is overwritten by the last created instance of the class (see the the Main Program). How do I define the onMouseDown function to point to a member function?


// Main Program
.
// Create and draw 10 fields
for (i=0;i<10;i++)
{
var field:CField = new CField(i*50, 50);
field.Draw(i);
}
.

My class is looking more or less like this:

// Field Class
class CField
{
// Properties
var m_nPosX:Number;
var m_nPosY:Number;
var m_mcField;

// Constructor
function CField(nPosX:Number, nPosY:Number)
{
this.m_nPosX = nPosX;
this.m_nPosY = nPosY;
}

public function Draw(nCount:Number)
{
var sInstance:String = new String(nCount.toString(10));
this.m_mcField = _root.createEmptyMovieClip (sInstance, nCount);
with (this.m_mcField)
{
_x = this.m_nPosX;
_y = this.m_nPosY;
loadMovie("Field.swf", nCount);

onMouseDown = function ()
{
trace("Mouse Clicked");
}
}
}
}

Inside XmlOnload Function Can Not Call Other Function Directly
I have a question, why the test function can not be called ?
Thanks.

Code:
class testClass {
public function testClass() {
var XMLData:XML = new XML();
XMLData.load("coonfig.xml");
XMLData.onLoad = this.xmlOnLoad;
}
public function xmlOnLoad(success:Boolean) {
if (success) {
// this.test();
test();
}
}
public function test () {
trace("test success");
}
}

Actionscript Function Similar To PHPs Explode Function?
Hello everyone, first off, I'd like to say hi to everyone as this is my first post and I have joined very recently! So yeah, I'm glad to be here and yeah, hope I find what I need.

Right, well for those of you who know PHP there is a function known as explode(), which basically splits a string apart by a certain character and throws it into an array.

For example, in PHP.


PHP Code:



$string = "lol,text,omfg,wow,hi";




I can explode that string by the , character and it would split up everything and throw each little "section" into an array.


PHP Code:



$bits = explode( ',', $string );




I can now access access the bits by $bits[0], $bits[1], $bits[2], $bits[3], and $bits[4].

Now, is there anyway you can do this in Actionscript? Say I have a string in actionscript and I've datatyped it to a string.


PHP Code:



var myString:String = "text1|text2|text3|text4";




How can I explode, or break apart, the string by the | character and get the "text1", "text2", etc, strings?

Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:


Code:
package
{
import flash.events.*;
import flash.net.*;

public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}

private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}



And is running the following code in my flash:


Code:
import SendAndLoad;
import flash.net.URLVariables;

function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );

//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}

var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();

sal.sendData( url, vars, loadUsername );



As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.

As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?

Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:

Code:
package
{
import flash.events.*;
import flash.net.*;

public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}

private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}


And is running the following code in my flash:

Code:
import SendAndLoad;
import flash.net.URLVariables;

function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );

//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}

var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();

sal.sendData( url, vars, loadUsername );


As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.

As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?

Functions Inside A Function Returning To Previous Function
This is a kind of long post so for your benifit here's some story Tags, if you don't want to read my sobbing story, then just look for the /story tag
<story>
Hello there, I'm trying to build a semi-combat system for a small RPG that I am making. I'm to the part where I am trying to make a combat system based upon AD&D 2nd Edition Rules, that's Dungeons and Dragons. It involves rolling for initiative, rolling Thaco(Deciding whether or not you hit), and then deciding on how much damage is inflicted.

So as I was trying to automate the task of choosing who goes first(Initiative), the long process of writing the code came about and I realized that I will have to write the same code twice. Once for the monster going first and again for the character going first.
</story>
What I want to do is to write a function that goes into another function if the parameters are met and then that function will test some more variables and if the variables don't agree, the function will resume from whence it broke off into the new function.

ActionScript Code:
function attackAction(){
    //Roll d10 for each party
    cr=Math.round(Math.random()*9)+1;
    this.cr_txt.text=cr;
    er=Math.round(Math.random()*9)+1;
    this.er_txt.text=er;
    //If the enemies roll is greater, then have him attack first
    if(er>=cr){
That's where a new function would come in. It would be something like

ActionScript Code:
function monsterTurn(){
    //Test Thaco
    if(Math.round(Math.random()*19)+1>=_root.monsterThaco){
    //Roll for damage amount
        damage=Math.round(Math.random()*_root.monsterAttack);
        //Display message of Damage and takes damage from you
        this.actions_txt.text="The Monster hits you for "+damage;
        this.Health-=damage
        //sees if the character is dead
        if(this.Health<=0){
        this.actions_txt.text="Oh no!  You died";
        }
        else{
        //Go back to the previous function and resume from there
Then of course there would be a playerTurn() that would do everything similar except test the player's variables.
<story>
If you're going to say that I should just have it list the commands, I tried that. It was far too long and complex to keep track of even with notes.
</story>

So can anyone help me out with Going through a function, hitting an if statement, going to a function based upon the statement, then testing a statement inside of the second function, then returning to the first function if the statement is false and doing the other part of the if statement in the first function.

It's difficult for me to explain this, but I hope you go the general jist. Thanks in advance.

Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
quote:package
{
import flash.events.*;
import flash.net.*;

public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
//var loader:URLLoader = URLLoader( event.target );
//trace( "Par: " + loader.data.par );
//trace( "Message: " + loader.data.msg );
//}

private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}

And is running the following code in my flash:
quote:import SendAndLoad;
import flash.net.URLVariables;

function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );

//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}

var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();

sal.sendData( url, vars, loadUsername );


As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.

As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?





























Edited: 10/09/2008 at 08:46:50 AM by _TT_

Function That Wait's 5 Seconds And Runs Anothr Function
hy...I want to make a function that waits 5 seconds, after that to run another function that changes the content (changeContent) to the next label

this is all i managed to do...I hope it's wright

function autorun() {
if (button_label = 0) {
changeContent(1);
} else if (button_label = 1) {
changeContent(2);
} else if (button_label = 2 ) {
changeContent(3);
} else if (button_label = 3) {
changeContent(4);
} else if (button_label = 4) {
changeContent(5);
} else if (button_label = 5) {
changeContent(0);
}
}

I need this in AS2.0....
Can someone help me? Thanks!

[F8] [AS2] Access An Instance Variable From Within A Function Within Another Function
So here is the scenario that has completely stumped me. I have a class, within the class a function and within that function an xml onload handler. So herein lies the problem, I need to store the array of values that I receive from the XML into an instance variable belonging to the class. How can this be achieved?

To illustrate:

Class A {private var values:Array;public function getValues():Void{Xml sendandload code here.xmlReply.onLoad = function(){iterate through xml code and generate array of values.Store this array back into values belonging to class A}}}

using the variable straight up doesn't work.
if I use "this" it refers to the onload function, not the class.
i tried creating another class method called setValue and calling this.setValue(arr) and setValue(arr), but neither of those work.
i even tried combinations of _parent and this, still no go.

The only way I can get it to work is to make reference to _root.class.value, but this is not solid code and is very impracticale, especially if what calls the class doesn't happen to be in the root of the file.

Any ideas would be appreciated.

How Can You Make Sure One Function Completes Before Second Function Runs?
Hi guys:

I apologize if it's a really obvious answer, but I can't even think of the right terms to search on right now!

I have two functions. One is an xml connector trigger, that calls a PHP program to get xml data that includes content and formatting information. It will read the formatting information into hidden text fields.

The second function reads the hidden text fields, and applies the data from them to the style for the content fields:

Here's the prototype (pooh just being a "foo" name), contained in the root of the application:

Code:
// Initial poll for the XML data (this also runs the PHP that updates the movie)
var f_xml_trigger:Function = function(){
xml_community_board_connector.trigger();
}
_global.f_xml_trigger = f_xml_trigger;

// Function to apply styles:
var f_format:Function = function(){
Dashboard_Message_TextArea.setStyle("backgroundColor",Pooh.text);
}
_global.f_format = f_format;

_global.f_xml_trigger();
_global.f_format();
What's happening is _global.f_format is running before _global.f_xml_trigger has completed populating the fields.

I made these Global so a movie clip that's running a clock can periodically check for and apply updated content & formatting.


Code:
function getTime() {
var time = new Date();
<snip>
var second = time.getSeconds();
<snip>

if (second == 30 && _global.t30flag == 1)
{
// The _global.t30flag is used to make sure this only runs once
// otherwise it would run at the frame per second rate (i.e. 12fps = 12 times
// during the 30th second

_global.f_xml_trigger();
_global.t30flag++;
}

if (second == 31 && _global.t30flag == 2)
{
// Apply the formatting brought down by the xml trigger.
// Can't be done at the same time, because it runs before the values are updated.
_global.f_format();
_global.t30flag++;
}

<snip>
But rather than depending on frame numbers or seconds (especially since a 1 second delay between when text changes and formatting changes is annoying to say the least!)...I would think there must be a way that as soon as we can get a success returned from _global.f_xml_trigger we can run _global.f_format.

Any suggestions?

Thanks,
Matt

Using Variables Created Inside A Function Outside The Function?
I am trying to use a variable I am creating inside of a function, outside of that function, but I seem to have a scope issue when I do this.

My code is:

Code:
function drawlines(centerx, centery, radius, radians){
var radiansSoFar:Number = 0

var piechart:MovieClip = new MovieClip();
piechart.name = "piechart"
piechart.x = stage.stageWidth/2;
piechart.y = stage.stageWidth/2;


stage.addChild(piechart);
}
but I want to make a function outside of this which removes the variable piechart, but because im so unfamiliar with how flash names instances now I have no idea how to do this.

It works if I define var piechart:MovieClip = new MovieClip() outside of the function, but this isnt very useful as I eventually need to create multiple movieclips dynamically and name them dynamically.

So basically how would make it so I would be able to use the code


Code:
function removeChart(chartname){
stage.removeChild(chartname)
}
to dynamically remove a movieclip I created in a function?

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