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




External Functions



Hi all,
I was wonering if anybody knows if it's possible to place a
gotoAndPlay(Scene ?, "?"); script in a html page so that when a html link is clicked it opens the html page and also sends the flash movie a location so that it doesn't go through the intro again.
I know that flash can talk to javascript but I have never attempted this and am a bit lost.
Any suggestions would be appreciated,
Simon



FlashKit > Flash Help > Flash ActionScript
Posted on: 09-13-2005, 12:07 AM


View Complete Forum Thread with Replies

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

External Actionscript And Calling External Functions
I have not been able to figure out or find a good tutorial on how to use external actionscript or how to call functions located externally. What I have found in flash help and livedocs has not proved to be helpful and I have not managed to make it work. Has anybody seen anything?

Even a simple thing, such as creating an external function that tells a button to go to the next frame and how to call that in my flash file would be greatly helpful.

External Functions In .as
Hye, I've not found answer anywhere so I post this message :
I've two .as with all the functions I need to use in my fla. Many functions are used in different movie clip.
In my two .as I've this :
function aaaa():Void {
.....;}

function bbbb():Void {
.....;}
.....
On the first frame of the scene in Flash I've :
#include "file1.as"
#include "file2.as"
When Flash or SEPY check the code I've an parse error in line 1 in file1.as (or file2.as if I include file2 before file1).
When I insert coment before the function in as files I've a parse error in line 1 with Flash and a parse error in line of the first function with SEPY.
I don't understand anything because if I remove the code from the functions I've this error anytime.
I'm in Flash MX (v6)
Thanks to help me.

Loading External Functions
Issit possible to load a .as file without flash embedding the codes into the swf. I try #include and it actually loads all functions into the swf. So I'm able to use a ActionScript Viewer to view the code. Is there anyway that I can load functions in without "embedding" it into the exported swf?

Calling Functions From External Swf?
This is my first attempt at using functions. I don't think I'm too far away!

I have a movie on the main timeline that declares the fuinctions in the first frame. I then load in a file called news.swf that tries to call thse functions but it always seems to relate it to the main timeline (i.e. goes and plays frame 4 of the maintimeline instead of the news.swf.) Here's the code:

1st frame of main timeline:

function preloader() {
loadedBytes = this.getBytesLoaded();
totalBytes = this.getBytesTotal();
if (loadedBytes == totalBytes) {
this.gotoAndPlay(4);
}
}
function barlength() {
loadedBytes = this.getBytesLoaded();
totalBytes = this.getBytesTotal();
percentageOutput = int((loadedBytes/totalBytes)*100);
bar._xscale = percentageOutput;
}
function preloadloop() {
if (loadedBytes<totalBytes || introBytes<introTotal) {
percentageOutput = int((loadedBytes/totalBytes)*100);
bar._xscale = percentageOutput;
this.gotoAndPlay(2);
} else {
this.gotoAndPlay(4);
}
}

preloader();

2nd Frame

barlength();

3rd Frame

preloadloop();

In the news.swf I have:

1st frame
_root.preloader(this);

2nd Frame
_root.barlength(this);

3rd Frame
_root.preloadloop(this);


I'm not sure if I'm using 'this' in the correct place. If anyone could give me more info on why and where to use 'this' I would be very grateful.

Thanks for your help,

Graeme

As Functions From External Text
Hi!!!
This is my question:
I have a dynamic text field (text) with a scrollbar that loads some external text (news.txt). And what i need is that after pressing a part of that text I would load an image (image1.jpg) into a empty movie clip (movieHolder), and another text file (content.txt) into a second dynamic text box (text_2).
I manage to load the image into the empty movie clip when i pressed the text, but i tried to associated a second AS function into the text to load the "content.txt" but i'm doing something wrong... because the function to load the text doesnt work.
here is my code

the AS for the swf:

function loadText(text) {
loadVarsText = new loadVars();
loadVarsText.load(text);
loadVarsText.onLoad = function(success) {
if (success) {
message_txt2.html = true;
// we want to use html in the text.
message_txt2.htmlText = this.titulo1;
// "myText" is var name in the text document.
} else {
trace("not loaded");
}
};
}
function loadPics(movie) {
movieHolder.loadMovie(movie);
movieHolder._alpha = 100;
}
loadText = new loadVars();
loadText.load("news.txt");
loadText.onLoad = function(success) {
if (success) {
// trace(success);
text.html = true;
text.htmlText = this.mytext;
}
};

and here is the news.txt that triggers everything:

myText=<p><b>28 junho 2005</b></p><A HREF="asfunction:loadPics, image1.jpg"><A HREF="asfunction:loadText, contents.txt"></A>
<p>press here to see the news<br/></p>


hope i made myself clear!!!! thanks a lot!!!!
cheers

HELP Calling Functions From External SWF'S
Guys, i need your help.. a designer just gave me this project. its a site about interior design. my job is to add some code to do something. i checked the code and his approach is not so good.. he's coding inside objects and frames at the same time. (ive read many actionscript books and this is a really bad practice).

Here's the problem... he wants this to be implemented in the site...

1.) in the gallery there is a scrolling thumbnails, he wants this to pause about 4 seconds then it will start to scroll..(ive already fixed this by creating a function interval. i just want to post the original instructions he gave to me)

Here is where my problem is...
2.) When you click the thumbnail, the enlarged view will pop up.. the enalarged view are external swfs... the client wants that when you click on the thumbnail, the scrolling will stop and the external popup enlarged image will come out... this external swf has an exit button to go back to the main gallery window which is another swf... so the client wants that when you hit exit from the external swf popup window, the scrolling will resume.... im having a hard time figuring this out because i dont know how to call a function from an external swf to the main movie (the gallery page) Ill post the fla of main movie, gallery and a single external swf link of the thumbnail. just click on the first picture that will appear on the gallery

Here are the source files.. Please guys, need your professional advice and help.

http://files-upload.com/files/445462/ExternalSWF.rar
http://files-upload.com/files/445479/Gallery.rar
http://files-upload.com/files/445465/Main.rar

thanks

Functions Embedded In External Swf Failed
Hi,
I´ve assembled a main swf which loads several external swfs
with the loadmovie command in a empty movieclips.
In the external swf, Í´ve several functions ( loading text in a dynamic textfield, starting a little movieclip ... ).

These works fine in test mode, but when loading the swf in the main movie, the buttons react on clicking, but the functions are not performing - the text doesn´t appear and the movieclip doesn´t start.

who knows ? I´ve tried a lot - perhaps not all. even to declare the functions as "_global"

thank you for answer

Rudi

Addressing Problems W/ External Functions
I'm testing the functionality of some code that makes a button scale along the y axis in a "springy" way. The code works fine when it's in the .fla file but only partially when I put the code in functions in an external .as file and then invoke the functions from within the .fla. (I use #include on the first frame of the main timeline, so it's the same as if I had put the functions there).

WHAT WORKS: First, I put code on a button that sets targets for scaling:

on(rollOver){
y_target = 160;
}

on(rollOut){
y_target = 100;
}

Second, I put the button into a movie clip and add the following clip events:

onClipEvent (load) { // this sets up some variables
y_scale = this._yscale;
vy = 0;
y_target = 100;
acc = 2.2; //increasing the acc variable SLOWS the process
b = 1.45; //increasing the b variable SLOWS the process
}

onClipEvent(enterFrame){ // this event controls the scaling
vy = (vy + (y_target - y_scale) *1/acc)/b;
y_scale += vy;
this._yscale = y_scale;
}


THE PROBLEM: When I put the code into functions in an external text file (called scripts.as, at the link provided below), the functions, once invoked on ANY instance, work on ALL MC instances on the stage. I've already made these functions part of the MC object using the formula Movieclip.prototype.functionName = function() . But I'm not sure what to do with the code that goes on the buttons.

You can download the files from: http://www31.brinkster.com/zjonbz/samples.html .

While reading the .as file, just ignore any lines that start with "HitFunction" or "ShowValue": they're just for debugging.

Thanks for any help & happy new year!

Targeting Scroller Mc Functions As External Swf
Hi everyone

Apologies for the double post but I could really do with some advice...I am having some problems targeting components of an external swf file. Basically I have followed a tutorial to make a vertically scrolling mc with a slider and a path. I have managed to get it working fine as a self-contained file, but I'm having problems when I load the swf into my main movie. I suspect it is to do with how I've targeted the slider button relative to the path and the content mc - I've been going around in circles supplementing '_root' with 'this' or '_parent' but haven't really got anywhere. When I load into the main movie, either the slider doesn't move along the path or the content mc doesn't scroll. I'm fairly new to actionscript but I'm guessing the problem is something to do with the targets. Can anyone have a look at this for me please and explain what I've been doing wrong? I've attached the file....

In case you can't open the attachent here's some code I'm using:

slider button:

on (press) {

startDrag(this, false, _parent.path._x, _parent.path._y, _parent.path._x, _parent.path._y+190);
}
on (release) {
stopDrag();
}


slider mc:

onClipEvent (load) {
setProperty(this, _x, int(_x));
}
onClipEvent (enterFrame) {
a = new Object();
a.y = this._y;
a.x = this._x;
_root.path.globalToLocal(a);
b = int(a.y*12.8);
}


path:

onClipEvent (load) {
setproperty (this, _x, _parent.slider._x);
setproperty (this, _y, _parent.slider._y);
}


cheers all!

Accessing External Javascript Functions
Hello,
I need to access an external js script that I have no control over.

In html, I use
<a href="#" onClick="function('parameters')">

In Flash, I used:

on (release)
{
getURL("javascript:function('parameters')");
}

(This is a global script that pops up a window and populates it with content -- I can't modify it)

It works GREAT on a mac, but on a pc, it returns the text "false" into the original window. This also happens if I use the same syntax in a regular html file. Is there any way I can use the original syntax in the flash movie (button)? I tried playing around with adding return statements, but flash wasn't too happy!

I'm using MX, publishing in flash 6

Thanks!

How To Access Functions In External Swfs?
Hey guys, just wondering how actionscript 3.0 deals with accessing functions in external swfs?

In actionscript 2 i would just load the external swf into a movieclip (eg: loader_mc) then i would just say loader_mc.animateIn().

I've tried the same thing in AS3 but it doesnt work... Can anyone tell me the new way of doing it?

Thx

External Link To .swf That Calls Functions
I was wondering if this was possible:

I want to link to a .swf file on a seperate page but also be able to call a certain function with the link.

Is this possible? Thanks

AS Functions On External Text File
Hi!!!
This is my question:
I have a dynamic text field (text) with a scrollbar that loads some external text (news.txt). And what i need is that after pressing a part of that text I would load an image (image1.jpg) into a empty movie clip (movieHolder), and another text file (content.txt) into a second dynamic text box (text_2).
I manage to load the image into the empty movie clip when i pressed the text, but i tried to associated a second AS function into the text to load the "content.txt" but i'm doing something wrong... because the function to load the text doesnt work.
here is my code

the AS for the swf:

function loadText(text) {
loadVarsText = new loadVars();
loadVarsText.load(text);
loadVarsText.onLoad = function(success) {
if (success) {
message_txt2.html = true;
// we want to use html in the text.
message_txt2.htmlText = this.titulo1;
// "myText" is var name in the text document.
} else {
trace("not loaded");
}
};
}
function loadPics(movie) {
movieHolder.loadMovie(movie);
movieHolder._alpha = 100;
}
loadText = new loadVars();
loadText.load("news.txt");
loadText.onLoad = function(success) {
if (success) {
// trace(success);
text.html = true;
text.htmlText = this.mytext;
}
};

and here is the news.txt that triggers everything:

myText=<p><b>28 junho 2005</b></p><A HREF="asfunction:loadPics, image1.jpg"><A HREF="asfunction:loadText, contents.txt"></A>
<p>press here to see the news<br/></p>


hope i made myself clear!!!! thanks a lot!!!!
cheers

Applying Functions To External SWFs
Hey guys,

First post here, and I need help...I'm a graphic designer trying to muddle through enough AS to create a bilingual site and I would apreciate it immeasurably if someone could offer me some advice with an AS dilemma. So here goes...

I start it off by setting a variable, "currentlang" upon clicking either the "english" or "french" button. Like so:

on (release) {
_global.currentlang = 1; //english
_parent.gotoAndStop(3); //action begins on the 3rd frame of main movie

}

or

on (release) {
_global.currentlang = 0; //french
_parent.gotoAndStop(3);

}

It seems to work fine. We're in.

Then I've created a function in my main movie that toggles the language back and forth from English to French by telling movie clips on the stage to go to the frame with French/English content. Here's the code on the timeline of the main movie:

toggleLanguage = function () { if (_global.currentlang == 0) {
content.gotoAndPlay(2);
_global.currentlang=1;

} else if
(_global.currentlang == 1){
content.gotoAndPlay(1);
_global.currentlang=0;

}
}

Here's the code on my button that I click to toggle back and forth:

on (release) {
_parent.toggleLanguage();
}

This works fine for the clips on the main movie, but what happens when I load in external SWF's. How could I make my function "toggleLanguage" talk to newly loaded clips? On the external clip I'm loading in, I have the following code on the timeline:

if (_global.currentlang == 1) {
this.header.gotoAndPlay(1);
} else if (_global.currentlang == 0) {
this.header.gotoAndPlay(2);
}


This works fine when the new movie loads in, meaning that if my "_global.currentlang" on the container movie is set to French, the loaded SWF will display "Bienvenue" rather than "welcome", and vice versa. The problem arises when I try to toggle the language. It only toggles the language of the clips on the main timeline and not the newly loaded ones. Like I said, any help would be greatly appreciated, as this is starting to drive me bananas, not being an experienced scripter and all.

Have at it!

Thanks!

Matt

_global Functions From External Swfs
hey everyone.

i have a dilly of a pickle (thank you ned flanders) that i cannot figure out for the life of me.

currently i am loading in a movie clip from a location online. that much works fine, however, in this external movieclip, it is making a _global function call to some code i have in my main swf which this clip is being loaded into.

if i take the swf and load it onto my machine and just call it from my own machine (ie/ mClipLoader.loadClip("file.swf", filePlace) instead of mClipLoader.loadClip("http://www.wherever.com/assets/**RANDOM FILE PATH**/file.swf", filePlace)) then the thing not only looks like it is working, but it will actually call my global functions... is there anything that would be causing this? Or perhaps if I uploaded it to their server it may work fine? (just thought of that now as I was typing... I am going to try it after I post this)

anyways, just let me know if you guys know anything.

thank you,

--d

External Swf Functions Won´t Work
I got problems to get the actions and functions of a external loaded swf.

Is there a trick to get all the stuff for making it readable for the main swf?

thx

Targeting Button Functions From External Movies
ok I've been trying to get some buttons to dropdown and look nice, and be functional, but I think I'm doing this wrong.. Firstly I have 4 buttons, each have submenu buttons which dropdown on the rollover, dropdown is an mc and the buttons are button instances. I've tried settingup a function on the maintimeline giving it a _global state, I've tried absolute addressing and direct addressing and I just can't get this to work!!! Can someone please point me in the right direction????

Many thanks

Paddy

[F8]How To Access Functions In External Swfs And Pass Them Variables?
Hi,

Im very close to the end of building my site, although i have one major issue i have to deal with.

Basically the homepage has links to different work in the portfolio and i need each of these to link to the correct sections of the external portfolio.swf (without having to create new swfs for each possibility...). I have a function called loadPortfolioSelection(); in the portfolio.swf:

function loadPortfolioSelection(selectedWork:String):Void {
currentPage = selectedWork;
this[selectedWork + "_mc"].gotoAndStop(7);
this[selectedWork + "Text_mc"].gotoAndPlay("_in");
mcLoader.loadClip(this[selectedWork+".swf"], this[selectedWork + "Loader_mc"]);
trace("It worked");
}


My problem is that i am unable to call this function from the main swf and pass it a variable.

My code inside home.swf is

portfolioLoader_mc.loadPortfolioSelection(page);

*The page variable holds the value i want (tested it with a trace(page))


I can't even trigger the trace command in loadPortfolioSelection(); so its obviously not executing this function. I've tried a number of different ways to execute the function but i just can't get it working.


Any help would be greatly appreciated.

Accessing Variables And Functions Between Loaded External Swfs?
Using AS 3.0: Say I have a menu.swf that loads a content.swf below it using the following

var newContent:Loader = new Loader();
newContent.load(new URLRequest("fowContent.swf"));
addChildAt(newContent,0);

Now say I have a frame label in newContent that is an animation ending the display of that swf. Upon clicking of another menu button in menu.swf, can I access the content's ending sequence by:

newContent.gotoAndPlay(newContent.endingSequence);

Also can you use while loops in AS 3.0? I would like to have a boolean variable "ended" in the newContent that becomes true after the ending animation has played.



while ( newContent.ended != true)
{
//wait
}

then have it run the function to load and display the new content.swf

Why Do Button Functions Included In External Actionscript Not Persist Across Frames?
this one drives me nuts!

if i include an external actionscript file in frame one of my movie, then [as you'd expect] all the functions, global variables etc contained in that external AS file are available throughout my movie - with one notable exception.

if i add a button to the stage - in a frame other than frame one - whose onRelease handler is defined in the external AS, the function is not called when the button is clicked - i have to re-include the external AS file again on the frame in which the button resides, in order for the buttons function to be called. anyone know why this is - and if there's a way round it?

how come all the other functions in the AS persist across all frames and all timelines in the movie, but the button handlers only seem to be available on the actual frame in which the AS file is included?


download example





























Edited: 01/26/2007 at 06:50:40 AM by madramadramadramadra

Dynamically Loaded Clips With External Images & Specific Functions
Hi fellow flash developers

I'm trying to build a little function that loads some variables from an online PHP file, where I get the number of existing elements, the correspoding thumbnails and the associated text for each. This elements are to be placed horizontally 120pix right after each other. For this, I chose to use a "for in" loop, that executes the number of times equivalent to the number of elements retrieved from the variable in the PHP file the SWF connects to.

Unfortunately the PHP file still doesn't have the paths to the thumbnails set in any variable, so for purposes of testing I am loading these thumbnails from the hard disk. They are in the SWF's folder.

The connection with the PHP is working fine, I am able to get the number of elements in it. The address if you want to check the variables, is http://www.imaginando.net/resin/traction.php .

So, in a more synthetic way, how do I get these images to appear on each corresponding clip I create, and how do I make them have a specific .onRelease function?

Going through the script helps to understand


Quote:




//declare the thumbnails's pictures array
releasesArray = new Array("RSI001small.gif", "RSI002small.gif", "RSI003small.gif", "RSI004small.gif");

//load the number of elements from the PHP
loadReleases = new LoadVars();
loadReleases.load("http://www.imaginando.net/resin/traction.php");
loadReleases.onLoad = function() {

//the number of elements is the variable ntractions
_global.numberOfElements = this.ntractions;

trace(numberOfElements); //this shows 10 in the output panel, there are 10 elements

//let this loop 10 times then.
for (i=0; i<numberOfElements; i++) {

//the next line of code is my attempt to set the "currentTractionImage" to "RSI001small.gif", doesn't seem to work

currentTractionImage = releasesArray[i];
trace(currentTractionImage); //this unfortunately outputs underfined

//get the button instance from the library (linkage id "traction_element", containing an MC with the instance name "holder_mc" where I would like to place an image from the SWFs folder, more precisely the actual [i] element of releasesArray:
var currentTractionItem = _root.attachMovie('traction_element', 'traction_element'+i, i);

//place the newly created item 120pix to the right
currentTractionItem._x += i*120;

//here I try to dinamically load the external GIF but the requested releasesArray's value is not retrieved
currentTractionItem.holder_mc.loadMovie(releasesAr ray[i]);

//the following command tests the button's activity, and works
//> //how do I apply a specific action for each?
currentTractionItem.onRelease = function() {
trace("button pressed");
}

//yet another yellow attempt to reach releasesArray's content
var imagetoLoad = ["RSI00"+i+"small.gif"];
trace("imageToLoad = " + imageToLoad); //outputs undefined
}
}

stop();




so.. that's my frustrated attempt to do it, and what fails is listed in the code's comments. If you see any mistake or any suggestion to make, I thank you in advance!

Made Functions Using For Loop, Trace Returns Undefined When Running Functions?
ActionScript Code:
var navAreas:Array = new Array("LOL", "WOOT", "ROFL");for (var f:Number = 0; f < navAreas.length; f++) {    this["action" + f] = function () {        trace(navAreas[f]);    };        // should make functions action0, action1, action2.}action1(); // shou'd return WOOT, but returns undefined.  

Dynamic Functions - Creating Functions At Runtime Without So Many Ifs/elses...
Hi, nice to register after lurking for a while and seeing how smart people are on here......

I am writing some code that needs to be very efficient, yet flexible. This is in a class and when the class gets initialized a function is setup. I want this function to run straight through without doing any time-consuming things such as calling other functions or routines, or doing any if/else logic/branching.

Now I know that you can setup a function at anytime during runtime such as:


Code:
var myFunction:Function = function() {trace('HELLO!')}
But what I am trying to do is to try and append code to a function based on logic, yet I don't want the function to be deciding this logic when it is running as it will only need deciding when the function is created.... imagine if it were a string it would be something like myFunction+="do somethingelse;" which would be the same as having initially setup myFunction as such:


Code:
var myFunction = function() {do something; do somethingelse;}
With this I seem to be having no luck

Here's an example where I setup the most compact/efficient function at runtime depending on what I want the function to do. Now this was fairly simple because when we create the function there are only a few possible variations, but I need someway of doing a function+= as my real code has quite a few variations and it would be a nightmare have a zillion if/else branches. REMEMBER I do not want any logic/decisions in the function itself as it to be the most efficient the function must be as compact as possible and run straight-through.


Code:
var dynamicFunction:Function;
//
// Setup the dynamic function & call it
// In this example outputs "Hello Jim" & "Goodbye Jim"
dynamicFunction = CrapSetupRoutine(true, true, "Jim");
dynamicFunction();
//
// Try and setup the dynamic function using a less ify/elsey (less complicated) routine & call it
// In this example it doesn't work if we try and make it say both Hello & Goodbye like above :(
dynamicFunction = SetupRoutineIWouldLike(true, true, "Jim");
dynamicFunction();
//
function CrapSetupRoutine(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// Far too many ifs/elses...but remember the function created cannot have any if/else logic or calls to other functions
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else if (sayHello and sayGoodbye) {
returnFunction = function () {
trace("Hello "+yourName);
trace("Goodbye "+yourName);
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
} else {
returnFunction = function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
//
//What I actually want the Setup function to resemble is this
function SetupRoutineIWouldLike(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// the ifs/elses are as minimal as possible, which is good
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
}
if (sayGoodbye) {
// the += below doesn't work.....so the question is how to append to it?????
returnFunction += function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
// The end
P.S. I knew the += would never work as this is a function and not a string. But at least if you think of the function as a string you'll get what I'm trying to do.....I suspect if it can be done it involves casting or something and maybe using strings initially??

Calling Functions In Main Movie From An External Loaded Movie?
Hey everyone

I have a preloader function in my main movie, that I would like to be able to use in the different SWF's that I load into new levels using loadMovie....

How do I refer to this? Can anyone take a little time to explain how..

- Rune

Variables/functions "pushed" To Root From External MC
*I moved this to the Actionscript forum.*

Multiple Functions Or Long Functions With For.. Statements?
Which is better? A long function with a couple of for... statements, or multiple functions with only one for... statement in it?

Andy

Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.

For example, here I am trying to set the private boolean member variable to the state of the checkbox.

//NOTE: This is an EventListener. Does this change something major?

private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}

This will output the following: "undefined checked: undefined"

Now in the function directly above it, I have the following function:

public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}

And this function will correctly output the checkbox name as well as update the position.

If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.

In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.

Any ideas? This is really annoying!

Thanks!!!































Edited: 06/27/2007 at 03:30:12 PM by JoMasta

[F8] Running Functions From Within Functions In A Class
For some reason, whenever I try to run a private function from within another private function in a class, it doesn't work.


Code:
private function getVars(theVar) {
switch (theVar) {
case "m" :
return this.m;
break;
case "nI" :
return this.nI;
break;
case "rX" :
return this.rX;
break;
case "rY" :
return this.rY;
break;
case "cX" :
return this.cX;
break;
case "cY" :
return this.cY;
break;
case "s" :
return this.s;
break;
case "a" :
return this.a;
break;
default :
return "";
}
}



Code:
private function cSpeed():Void {
// ccX is just a placeholder for the cX variable
// so that the function can use it.
var ccX:Number = cX;
m.onMouseMove = function() {
s = (this._xmouse-ccX)/1500;
getVars("m");
}
}


I just used getVars("m") for the hell of it...just to see if it would work...but it didn't. Any idea why not?

[F8] Calling Functions Within OnEvent Functions.
Ive just stumbled upon an annoying problem, Im writing a custom class which, in its constructor attaches a movie clip to a main one (passed in as a parameter).
this all works fine.
My problem arises when i try to, also in the constructor, create an onRollOver event on the movieclip i attached earlier (its stored in a field).

The onRollOver event works fine, calling the trace statement ive been using, but it won't call any function which i ask for.


this is the code where im having issues:


Code:

function Corner(xPosition:Number, yPosition:Number, circ:Circle, deep:Number, baseClip:MovieClip)
{
this.image = baseClip.attachMovie("Corner","CornerX",deep);
this.image._x = xPosition;
this.xPos = xPosition;
this.image._y = yPosition;
this.yPos = yPosition;

this.circle = circ;

this.image.onRollOver = function()
{
trace("debugOne"); //this trace statement works fine

this.otherFunction(); //Problem is here, The code wont call this function for some reason
}

this.depth = deep;
}

function otherFunction()
{
trace("debugTwo");
}
any ideas why its not calling my function?

[F8] Functions Inside Functions? Urgent
Hi, is this in any way valid?


Code:
this.onRelease = function(){
_root.mainbutton(){
freeze == false;
}
i have a set of buttons id like to play their animations when i press a button. Can this be done?

Any help or pointers would be greatly appreciated, thanks!

Declaring Functions In Other Functions And Callbacks
Hi - I'm curious to know if the following situation is possible (I haven't gotten it to work yet).

I'd like to load a series of images, and in the callback, place them in different positions in my array. Instead of writing a separate callback for each image, I'd like to do something like the following:

But it looks like each version of the function gets the end version of "i", not the version of i that existed when the function was declared.

Is something like this at all possible?







Attach Code

public function loadImages():void
{
for (var i:int = 0; i < 4; i++)
{
function myCallback(e:Event):void
{
myArray[i] = Bitmap(e.target.loader.content);

}
loadImageWithCallback(image, myCallback);
}
}

Functions Passed As Arguments To Other Functions
FLASH MX 2004 - AS2.0

I have a function with 4 necessary arguments (aka parameters) in order to perform the actions. I would like to have the ability to pass the same function to itself as an argument (sort of like a recursive function) along with its arguments. Basically I want to "base" to engage an onMotionFinished event handler if there is another function passed as an argument. Something like...


PHP Code:



   function base (arg1, arg2, arg3 arg4, {arg5:another function, arg6:arg5s arg).....}){  //do the stuff  instructions = blahblahblah  if (arg5 is present){     instructions.onEventHandler = function(){         //perform function which is arg5...argN     }  } } 




Would there be a way to use listeners to do this or the AsBroadcaster? Thanks

Functions Trough Functions...
Hi, I have some problems with relative/absolute functions...
The code is:

--------Main.fla:


Code:
import Bus;

var aBus:Bus=new Bus(wooz);

function wooz()
{
trace("wooz!!");
trace(this);
}

this.onMouseUp=function()
{
wooz();
}

wooz();
aBus.TryCallback();

---Bus.as



Code:
class Bus
{
var _couleur:String;
private var _Func:Function;

function Bus(Func:Function)
{
trace("exec func...");
_Func=Func;
}

function TryCallback()
{
_Func();
}
}
I would like to have an output like this:

wooz!!
_level0
wooz!!
_level0



...But i obtain this


wooz!!
_level0
wooz!!
[object Object]

I would like to keep _level0 as this, and not object, who aBus

Can U help me please???

thanks

Trace A Functions Name From Within Functions
I am setting up a series of function. I want to use the function name as a variable inside each function like this:

var thisFunction;

function functionName(){
thisFunction = this.name
trace(thisFunction)
}

I want to set funcName to the the name of the function, someName.
Thanks in advance!

Functions Inside Functions?
Hello all -

The following code is in a external AS file that is called in the first frame of the movie. When I have it play outside of a function, it works fine. As soon as I put inside a function, it does not work. The code is


ActionScript Code:
var _mcl:MovieClipLoader = new MovieClipLoader();
var _listener:Object = new Object();
_listener.onLoadInit = function(_mc:MovieClip)
{
    trace("Done loading...");
}
_mcl.addListener(_listener);


this._mcl.removeMovieClip(clip_1);
this.createEmptyMovieClip("clip_1", this.getNextHighestDepth());
_mcl.loadClip("back.swf", clip_1);

I am new to AS, so I am trying to figure out if something in this code is not allowed when I put it into a function. I tested the function using trace statements to make sure it was being called and it was, so the problem seems to lie in this code. Does anybody know why this code will not work when put in a function? Thanks!

Functions Calling Other Functions
what i need to do is call a set of functions several times in sequence with different parameters each time. here's what i've got

Code:
/////photoload code////
this.fadeSpeed = 10;
this.fadeSpeed2 = 10;
var picToLoad = "";
var whereToLoad = "";

MovieClip.prototype.changePhoto = function(ddd,whatwhat) {
this.picToLoad = ddd;
this.whereToLoad = whatwhat;
trace("this.picToLoad = ddd **** "+this.picToLoad+" + "+ddd);
trace("this.whereToLoad = whatwhat ***** "+this.whereToLoad+" + "+whatwhat);
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.whereToLoad._alpha>this.fadeSpeed) {
this.whereToLoad._alpha -= this.fadeSpeed;
} else {
this.loadPhoto2();
}
};
MovieClip.prototype.fadeOut2 = function(xox) {
trace("fadeOut2 function called");
this.whichToFade = xox;
if (this.whichToFade._alpha>this.fadeSpeed2) {
this.whichToFade._alpha -= this.fadeSpeed2;
}
};
MovieClip.prototype.fadeOut3 = function() {
trace("this.whichToFade = "+this.whichToFade);
if (this.whichToFade._alpha>this.fadeSpeed) {
this.whichToFade._alpha -= this.fadeSpeed;
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.sectImg;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
//this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadPhoto2 = function() {
// specify the movieclip to load images into
var p = this.whereToLoad;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.picToLoad);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.whereToLoad.getBytesLoaded();
t = this.whereToLoad.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.whereToLoad._alpha<100-this.fadeSpeed) {
this.whereToLoad._alpha += this.fadeSpeed;
} else {
this.whereToLoad._alpha = 100;
this.onEnterFrame = null;
}
}
and then i've written the following to run the above functions:


Code:
MovieClip.prototype.controlPhoto = function(props) {
var ddd;
var whatwhat;
trace("arguments.length = " + arguments.length);
trace("props = "+props);
trace("arguments = "+arguments);
for (var cpi = 0; cpi<arguments.length; cpi++) {
trace("------ "+ cpi + " ------");
trace("arguments[cpi] = "+arguments[cpi]);
var my_array:Array = arguments[cpi];
my_array.slice();
trace(my_array[0]+" *** "+my_array[1]);
ddd=my_array[0];
whatwhat=my_array[1];
this.changePhoto(ddd,whatwhat);
}
}
and i'm calling this function like this:

Code:
curr_item.onRelease = function() {
_root.controlPhoto([this.img1,sectImg],[this.img2,leadImg]);
}
but what happens is only the last set of parameters actually get loaded. everything else seems to be skipped over. any help is appreciated!
thanks,
david

Mc Functions Inside Functions
I created an empty movie clip. The object in the clip is drawn with actionscript.

I wanted for the object to do different things when different keys were pressed. Like so:

ActionScript Code:
clip.onKeyDown = function() {if (Key.getCode() == Key.DOWN) {clip.onEnterFrame = function() {_root.callFunction();}} else if (Key.getCode() == Key.UP) {clip.onEnterFrame = function() {_root.callFunction();}}}

It's a simple example showing that the onEnterFrame function does about the same thing for each keys. Am i doing this right, or can the onEnterFrame function be defined once and i can call it from the onKeyDown function?

Thanks,
Jerome

Functions Calling Other Functions
what i need to do is call a set of functions several times in sequence with different parameters each time. here's what i've got

Code:
/////photoload code////
this.fadeSpeed = 10;
this.fadeSpeed2 = 10;
var picToLoad = "";
var whereToLoad = "";

MovieClip.prototype.changePhoto = function(ddd,whatwhat) {
this.picToLoad = ddd;
this.whereToLoad = whatwhat;
trace("this.picToLoad = ddd **** "+this.picToLoad+" + "+ddd);
trace("this.whereToLoad = whatwhat ***** "+this.whereToLoad+" + "+whatwhat);
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.whereToLoad._alpha>this.fadeSpeed) {
this.whereToLoad._alpha -= this.fadeSpeed;
} else {
this.loadPhoto2();
}
};
MovieClip.prototype.fadeOut2 = function(xox) {
trace("fadeOut2 function called");
this.whichToFade = xox;
if (this.whichToFade._alpha>this.fadeSpeed2) {
this.whichToFade._alpha -= this.fadeSpeed2;
}
};
MovieClip.prototype.fadeOut3 = function() {
trace("this.whichToFade = "+this.whichToFade);
if (this.whichToFade._alpha>this.fadeSpeed) {
this.whichToFade._alpha -= this.fadeSpeed;
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.sectImg;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
//this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadPhoto2 = function() {
// specify the movieclip to load images into
var p = this.whereToLoad;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.picToLoad);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.whereToLoad.getBytesLoaded();
t = this.whereToLoad.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.whereToLoad._alpha<100-this.fadeSpeed) {
this.whereToLoad._alpha += this.fadeSpeed;
} else {
this.whereToLoad._alpha = 100;
this.onEnterFrame = null;
}
}
and then i've written the following to run the above functions:


Code:
MovieClip.prototype.controlPhoto = function(props) {
var ddd;
var whatwhat;
trace("arguments.length = " + arguments.length);
trace("props = "+props);
trace("arguments = "+arguments);
for (var cpi = 0; cpi<arguments.length; cpi++) {
trace("------ "+ cpi + " ------");
trace("arguments[cpi] = "+arguments[cpi]);
var my_array:Array = arguments[cpi];
my_array.slice();
trace(my_array[0]+" *** "+my_array[1]);
ddd=my_array[0];
whatwhat=my_array[1];
this.changePhoto(ddd,whatwhat);
}
}
and i'm calling this function like this:

Code:
curr_item.onRelease = function() {
_root.controlPhoto([this.img1,sectImg],[this.img2,leadImg]);
}
but what happens is only the last set of parameters actually get loaded. everything else seems to be skipped over. any help is appreciated!
thanks,
david

Using Functions To Define Functions
Hi all,

I'm trying to recode an MX script to F5, and its not working.

on a mc 'mcGoalie' i have the code;

onClipEvent(enterframe){
this.moveGoalie';
}

on root timeline:

function moveGoalie(){
....
}

so at the beginning, the prototype is not defined, so nothing happens.
then on a button (to start the game) i have the code

on(press){
Movieclip.prototype.moveGoalie=_root.moveGoalie();
}

then to stop

on(press){
Movieclip.prototype.moveGoalie=undefined;
}

which works.

problem is, i want a general startGame function to get everything going.

function startGame(){
Movieclip.prototype.moveGoalie=_root.moveGoalie();
}

then on start button

on(press){
_root.startGame();
}

which doesn't work.
can use use functions (here startGame) to define other functions and Movieclip prototypes? if not anyone know of a work around?

cheers

s[H]ura

Functions
Can functions be "called" in frames? I've experimented with "calling" functions within buttons...no prob there, but if I want to "call" it in the last frame of a clip, for example, will it work?

red penguin

A Bit Of Help With Functions
hey all, i was wondering if anyone knew the easiest way to make "global" functions

ones that i could access from any movie clip, at anytime

i tried putting them all in a movie clip but i couldn't get them to execute right after.

Fun With Functions
I'm relatively new to this actionscript malarky, and am having a bit of trouble with functions: I want to be able to reference a number of instances with one 'word'. I presume to do this with functions rather than a variable. Any help may or may not be financially rewarded! M

Functions
Hi! long time no word but now I'm back

Have a question - how to delcare and call functions in Flash? I guess functions are useful just like in C or Pascal... so I want to use them... please give me some directions.


Thanks in advance....
Star

Functions
when you define a function from a movie clip, can you use it on all levels or just that specific mc?

Key Functions? Please Help.. 911
First off, thank you for any replys.

I am creating a Flight Sim, and using flash for a little bit of it. I need to know if it is possible to use a JoyStick with Flash.. Kinda like on key press, but with a Joystick. It there AS or anything to do this?? Maybe a plugin? Or would I have to use like VB6 or something?

Also, How do you do object collision? to where if something moves over another thing it performs an action. Like on MouseOver, but when you move a MC with Keys or JS.. so like... on MC over. So when the MC goes over a button it does something? Any ideas? Thank's for everything guys!

-Paradoxz

Functions?
I am trying to understand Functions alittle better but am haveing trouble (Obviouslly).
I want to make a function that would change the properties of a MC. I have a MC with a button in it.
on (press){
move();
}
Then I have the function set up on the main stage frame 1:
function (){
for (i=0;i<10;i++) {
_x = _x+i;
}
}

but that doesn't work. What am I doing wrong? Do I have to put something in the () on the button or the function? Can some one please explain this to me and show me a code that does work. Thi8s is just an example not really important work here, but I do want to understand it.

Ahh Help Please With Functions
hello:

Is it that difficult to call a function? Ok here goes, I have a movie clip that has a loadmovie(url) like this:
function mySong(){
loadmovie("/whatever.swf",_root.movieclipName);mySound = new Sound(); mySound.attachSound(whateversong);mySound.start. Ok thats the movieclip code I add the movie clip to my main stage and I have a button that I want to call the function...how can I do that Help please...thanks in advance

Functions
How to use to place MC's randomly on the stage? So far my code is:
---------------------------------------------------------
onClipEvent (enterFrame) {
this._x = random(300);
this._y = random(100);
}
---------------------------------------------------------
can anyone help with this?

Functions
Hello,
I am trying to make a function that will attachMovie() at a certian location then animate it. Like this:

function flare() {
attachMovie("flare","flare1",1);
_root["flare1"]._x = 200;
_root["flare1"]._y = 200;
if ( _root["flare1"]._x < 400) {
_root["flare1"]._x++;
}else{
removeMovieClip();
}
}
I know this script is not even close to being right. That's why I'm here.
Any input would be great. Thanks in advance.

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