Function Inside A Function
Hi everyone, Is it possible to activate a different function inside a function by using action script?
Maybe this sounds unclear? What I aim for is something like....
This.onChanged = function() {// start function on changed data field bla bla bla, and some text.// (the function) Do function X;// redo function X }// end function
Do I in order to achieve this give the function a name between the brackets? function()
If anyone has some time left after reading this to visit my other problems that would be great. How to remove NaN from textfield adding formula inside datagrid
All help is apreaciated
Kind regards, Sebastiaan
FlashKit > Flash Help > Flash ActionScript
Posted on: 12-05-2005, 09:31 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
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");
}
}
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.
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?
Pausemovie Function Inside Fadein Function
Last edited by pusherman : 2007-06-21 at 10:26.
I am trying to merge two functions together. The result is however, pausemovie function does not work (perhaps overriden by onEnterFrame) and mypic's alpha reaches 100 by increments of 7.
ActionScript Code:
//MC:mypic1 appears.
createEmptyMovieClip("fadein", 222);
fadein.onEnterFrame = function() {
pauseMovie(4);
if (mypic1._alpha<100) {
mypic1._alpha += 7;
} else {
removeMovieClip("fadein");
}
};
My pausemovie function is on my 1st frame and is as follows:
ActionScript Code:
function pauseMovie(seconds) {
stop();
var startTime = getTimer();
var endTime = seconds * 1000;
this.onEnterFrame = function(){
currentTime = getTimer();
if(currentTime - startTime > endTime){
//this is where your action goes
play();
delete this.onEnterFrame
};
};
};
I would appreciate any help.
Thank you.
Placing A Function Inside A Function
Hey everyone,
So I'm not very effecient with actionscript and i'm trying to simplify some code. the bottom line is that that i want to call a function within a function. i have no idea what code to use to do that. I did use it in one part, although i'm not entirely sure how that works(yah code snipits off the net).
function homeOn() {
// send second children back
movieclipTweenOut(strategyBtn_mc, 831, 85, 100, 100, 0);
movieclipTweenOut(strategyBtnLine_mc, 807, 75, 100, 0, 0);
movieclipTweenOut(historyBtn_mc, 831, 85, h, h, 0);
movieclipTweenOut(historyBtnLine_mc, 770, 111, h, h, 0);
// send first children back
var tween_handler:Object = new Tween(strategyBtnLine_mc, "_alpha", Elastic.easeOut, 100, 0, 3);
tween_handler.onMotionFinished = mainButtonsIn;
};
so where the //send children back code is, i'd like to make a function so that i don't have to keep calling that every time, like this:
function subAboutUsIn(){
movieclipTweenOut(historyBtn_mc, 831, 85, h, h, 0);
movieclipTweenOut(strategyBtn_mc, 831, 85, 100, 100, 0);
movieclipTweenOut(strategyBtnLine_mc, 807, 75, 100, 0, 100);
movieclipTweenOut(historyBtnLine_mc, 770, 111, h, h, 0);
};
if anyone has any ideas, that would be great. it's probably very simple, i just can't figure it out. i uploaded the file too incase u need to check it out.
thanks
Call A Function From Inside Another Function?
Hey Guys,
Having a bit of a problem here
Just say this was the case on the main timeline
ActionScript Code:
function topFunction(){
trace("you just called the topFunction")
}
function testFunction(){
function nestedFunction(){
topFunction();
}
}
How the hell do i run the topFunction from inside nestedFunction();. In AS2 if i wanted to reference it i would type _root.topFunction(); but now I don't know how to get to it.
I just need to know how to reference variables and functions from anywhere in my actionscript if i'm in another scope or in another MC.
Thanks guys
Calling A Function Inside Another Function
Hi All,
I've set up two functions (friendsClick and policyLink) I would like to use everything inside of friendsClick inside of policyLink but I'm not sure how to go about doing it. I get the following error:
1136: Incorrect number of arguments. Expected 1.
My code looks similar to:
Code:
function policyLink(e:MouseEvent){
friendsClick();
"all my other info here"
}
I can just copy everything from the friendsClick function and paste, but I'm trying to limit my amount of repetitive code (I'm trying to get better at that). Please Help.
Calling A Function Inside Another Function
Hi i've created some functions that run when diffrenent buttons are pressed, and they work fine, but i want something else to do the same thing when any of the buttons are pressed, i thought the easiest way to do it was to create a function and call it each time one of the buttons are pressed. but what is the code to run the function??
all the code is on the main timeline..
i've wrote this and it doesn't work....
the function i want to run is:
brentGandS = function (){
_root.menu_mc.brent_mc.tween("_width",200,5,"easeoutelastic")
}
and the on press function is:
menu_mc.contact_btn.onPress = function() {
window_mc.resizeTo(250, 350, speed, "easeoutelastic", onEnda);
brentGandS
};
any ideas????????
Call A Function Inside A Function
I have a function that attaches a movie clip and names it movieClip_1. I now need the to call the same function again to create movieClip_2 when you click movieClip_1.
Function Inside A Function
function inside a function
why it doesnt work? Do anyone know how can I use the "press" instruction for button inside a function?
this is something I am working
function makeMove(){
// Have a shoot
if(myMove=="T"){
target1.btnHit.onPress = function (){
trace("hit")
}
if (_root.count <0){
trace("over")
}
} else{
yourMove();
}
}
Function Inside A Function
getOccurances function is not called.
Code:
keylistener = new Object();
keylistener.onKeyDown = function()
{
if (Key.getCode() == 65)
{
//Some code
var letterAs:Array = getOccurances(string, "A");// it dosn't call getOccurances
function getOccurances(string:String, letter:String):Array {
var index:Number = 0;
var letterIndex:Number = string.indexOf(letter, ndex);
var indexes:Array = new Array();
while (letterIndex != -1) {
indexes.push(letterIndex);
index = letterIndex+1;
letterIndex = string.indexOf(letter, index);
}
return indexes;
}
Key.addListener(keylistener);
Function Inside A Function
I basically need to run a function inside a function in actionscript, and am having trouble. Basically, nothing in bold is being applied. Any ideas? Thanks!
Code:
var myVariable:LoadVars = new LoadVars();
myVariable.load("http://www.myURL.com/ad/store/baby/demo.asp");
myVariable.onLoad = function(success:Boolean) {
if (success) {
var Tester2:MovieClip = _root.MainMovie.Img2.createEmptyMovieClip("imgHolder", 1);
var mcl2:MovieClipLoader = new MovieClipLoader();
var mclListener2:Object = new Object();
mclListener2.onLoadInit = applySmoothing2;
mcl2.addListener(mclListener2);
mcl2.loadClip(this.Image2, Tester2);
function applySmoothing2(target2:MovieClip) {
var mcParent2:MovieClip = target2._parent;
var mcName2:String = target2._name;
var myBitmap2:BitmapData = new BitmapData(target2._width, target2._height);
myBitmap2.draw(target2);
target2.removeMovieClip();
target2 = mcParent2.createEmptyMovieClip(mcName2, mcParent2.getNextHighestDepth());
target2.attachBitmap(myBitmap2, 1, "auto", true);
}
}
}
SetInterval Inside A Loop Inside A Function - Am I Crazy?
I've got a menu loading from XML data - however I'd like the mc's to appear sequentially, maybe 1/10th second apart. I know setInterval should do this, but I'm still new to flash and despite trawling Google for 24 hrs solid, nothing seems to show me the right way.
Here's the script:
Code:
function CreatePortMenu(port_xml)
{
var portClients = port_xml.firstChild.childNodes;
var xPos = 0;
var yPos = 0;
var xSpacing:Number = 90;
var ySpacing:Number = 35;
var i = 0;
for ( i = 0; i < portClients.length; i++ )
{
switch (i) //splits the menu items into columns of 4 (max 12 items)
{
case 0:
case 1:
case 2:
case 3:
yPos = ySpacing * i;
break;
case 4:
case 5:
case 6:
case 7:
xPos = xSpacing * 2;
yPos = ySpacing * (i - 4);
break;
case 8:
case 9:
case 10:
case 11:
xPos = xSpacing * 3;
yPos = ySpacing * (i - 8);
}
var currentClient = portClients[i];
var portHold = portHolder_mc.attachMovie( "jobOption", "pb"+i, i, {_x:xPos, _y:yPos});
portHold.jobTitle.jobText.text = currentClient.attributes.title;
}
}
So I *think* I should be inserting two lines, one creating a setInterval, and one clearing it, but where? Some guides say inside the function, some say outside, some say only the clearInterval should be inside, some have the function inside the loop... I also *think* I've tried every possible combination, but no soap. Please help!?
Using SetInterval Inside A Function, Inside A Loop
I'm very confused by this now
I'm trying to use setInterval to delay what happens on a rollOut function, which is added to every button inside a loop.
Can anyone help me with the syntax, I'm totally lost!
Thanks,
James
PHP Code:
for (var i = 0; i<=(node.length); i++) {
currentButton.num = i-1;
//----attach the projectButton movieclip from the library----//
attachMovie("projectButton", "projectButton"+i, i);
//----move the button to the right place----//
currentButton = _parent.portfolio["projectButton"+i];
currentButton._y = 1+(26*k);
currentButton._x = 2+(230*j);
//----put the name of the project onto the button----//
currentButton.projectID.text += node[i].attributes.title;
//----rollover function----//
currentButton.onRollOver = function() {
currentButtonNow = _parent.portfolio["projectButton"+this.num];
currentButtonNow.projectID.text = "";
currentButtonNow.projectID.text += node[this.num].attributes.description;
};
//----rollout function----//
currentButton.onRollOut = function() {
APause = setInterval(GoBack2, 500);
//calls a function called GoBack every 'x' seconds//
function GoBack2() {
// SOME FUNCTION HERE!!!!!!!!
clearInterval(APause);
trace('clearing interval of '+currentButton.num);
}
currentButtonNow = _parent.portfolio["projectButton"+this.num];
currentButtonNow.projectID.text = "";
currentButtonNow.projectID.text += node[this.num].attributes.title;
};
//----release function----//
currentButton.onRelease = function() {
loadMe = node[this.num].attributes.id;
gotoAndPlay(10);
//gotoAndStop("portfolio");
};
//---- take out the leftover one idiot ----///
if (currentButton.projectID.text == "undefined") {
_parent.portfolio["projectButton"+i].removeMovieClip();
}
//---- watch the old variables mr greig ----//
k++;
//---- slit the list into 2 columns at which point? ----///
if (i == (8)) {
j = 1;
k = 0;
}
Var Inside Function
Hi,
I know this has been asked before but no solid answer yet.
I want to declare a var inside a function and then access it from the outside. This does not work. I know i can do it with classes or declaring it from teh outside but for this project it would be to complex. So please, is there any way of declaring a var inside a function and get access to it from the outside.
Example:
init()
function init () {
var myVar=12345
}
trace(myVar)
//Result = 1120: Access of undefined property myVar.
[AS2] Run Function Inside MC
I've got an MC on the first frame of the _root timeline called "mc"
Inside of "mc" is a function:
ActionScript Code:
function init():Void{trace("init()");}
If I only have 1 frame in the main timeline, and on that timeline I call mc.init(); nothing happens.
If I have 2 frames in the main timeline and on frame 2 I call mc.init(); the function is successfully called.
Why is this? Why can't I call mc.init(); on the first frame?
How To Execute A Function Inside A MC ...
Hello, here me problem:
I have a function init() inside of my mc.
This function set the colour of the object.
But, i dont know hy, i can't execute it!
Strange things happen.
What i want is called the function, set the color and
play the movie. The movie must not run 'till it's initialised because the value set is used in the next frames.
The mc is in the libtairy, and I use attachMovie()
to attach it to root ..
Tnx!
Variable Inside A Function
Button code:
[code]
on(release){
function textSwitch(mission, mike);
}
Code:
function textSwitch(screen, item){
_root.text = content[screen][item];
}
content.mission.mike = "I am mike";
content.mission.dani = "I am dani";
content.mission.dale = "I am dale";
I know something is wrong with the way I'm implementing the the passed variables into the function. Specifically, content[screen][item] I think is incorrect. Could you tell me how to fix this?
Function Inside A Loop
Hello.
I have a problem with tis loop or the function. It always outputs 16 when I click the buttons, but I want each button to output a number that is the same as the number on the movieclip.
for(i=1;i<=15;i++){
duplicateMovieClip(movie_mc, "movie"+i+"_mc",i);
_root["movie"+i+"_mc"]._x = -200 + 100*i;
_root["movie"+i+"_mc"]._y = 0;
_root["movie"+i+"_mc"].button_btn.onRelease = function(){
trace (i);
}
}
Please help me!
Wait Inside A Function?
Is there a way to wait inside a functino code until something happens?
Basically I have a function that loads an xml. however, since it takes certain time, my function returns the control even before onLoad is called.
How do I make the function wait for that onload call and proceed to return?
thanks
-Mav
Need To Pause Inside A Function.
Hello people,
I have a function that tells other movies to do stuff, but I need that to happen in a timely manner. Do you know a way that I can insert a pause inside the actual funciton, so that it doesn't go to the next command until the time is right.
function(){
do this....
wait(time1)
do that.....
wait(time 2)
and like that
thanks in advance
Calling A Function From Inside An MC
Is it possible to call a function from inside an mc? I have:
MovieClip.prototype.scrollme = function(xPos){
this._x -= (this._x-xPos)/5;
};
//initialise a variable
var xPos:Number;
xPos = menu._x;
_global.out;
out = false;
//menuMC actions
menu.EnterFrame=function(){
if (out) {
//call the prototype and provide a target xpos
this.scrollme(-723);
} else {
this.scrollme(-315);
}
}
so, I have buttons two mcs INSIDE of this one that should scroll the whole menu to the left when called- I can't seem to get it to work. I've tried calling the function (scrollme(-723)), and setting the variable out=true. It doesn't budge. Is there any reason why this shouldn't work?
Thanks so much, time is running out!
miakazi
Using Function Inside Movieclip
Hi People,
How do I refer to a button in side a movie clip and have the buttons action function inside the main scene.
This is the script is inside first frame in my actions layer on the main scene.
rem1_but.onRelease = function() {
if (zone_1._currentframe !=1) {
removeFromZone(zone_1,1);
//--close the preview mc if it is open
if (previewMC !=underfind){
previewMC.removeMovieClip();
}
}
};
I need it to work when the button (rem_1but) is inside a movie clip called zone_1.
Thanks for you time.
SetInterval Inside Of A Function?
I can't seem to get the interval to call the function to play the next frame... Any help? thanks. I've tried to take out the single quotes.
code: function interval (btn, dir) {
function next () {
nextFrame ();
}
function back () {
prevFrame ();
}
btn.onEnterFrame = function () {
this.onRollOver = function () {
id = setInterval (dir, speed);
};
this.onRollOut = function () {
clearInterval (id);
};
};
}
interval (btn,'next')
interval (btn_back,'back')
Going To A Preloader() Inside A Function
Hello,
I have a function that is meant to load a certain movie on Level10, and then go to a certain keyframe, but I need to preload that movie before I can tell it to go to frame XYZ. Does anybody know how I can go out of a function to a preloader, and then come back in? In other words
function loadMovie_fnc(){
......
......
loadMovieNum("intro.swf", 10)
preloadMovie();
gotoAndPlay("end");
}
Thanks in advance
Use Variables Inside Function
My first post!!!
Here's the issue I'm facing:
for (i=0; i<total; i++) {
boatname[i] = xmlNode.childNodes[i].childNodes[0].attributes.bname;
_root["boat"+i].bname2.text = boatname[i];
_root["boat"+i].onRelease = function() {
lrg._alpha = 0;
lrg.loadMovie(piclrg, 0);
_root.boatinfoxxx.bname.text = boatname[i];
};
}
This script works but when I view "_root.boatinfoxxx.bname" it's showing is as undefined. Now this is cause the "boatname[i]" in the function isn't working. How can I pass that array with the variable number in to the function to get it to work?
I've looked around the board but couldn't find an answer. Can some one please help me!
Two Conditions Inside A Function
what is the syntax to write?
and how can i structure the code if there're two conditions to fultil in a function?
i've got this , but it don't seem to work.
PHP Code:
function theFunction() {
xxx.onEnterFrame = function() {
a?b:c;
d?e:f;
};
}
Two Conditions Inside A Function
what is the syntax to write?
and how can i structure the code if there're two conditions to fultil in a function?
i've got this , but it don't seem to work.
PHP Code:
function theFunction() {
xxx.onEnterFrame = function() {
a?b:c;
d?e:f;
};
}
Button Inside A Function
Do anyone know how can I use the "press" instruction for button inside a function?
this is something I am working. but it doesnt work. If I get the press function out of this makeMove function, it works.
function makeMove(){
// Have a shoot
if(myMove=="T"){
target1.btnHit.onPress = function (){
trace("hit")
}
}
Use Of Button Inside A Function
Do anyone know how can I use the "press" instruction for button inside a function?
this is something I am working. but it doesnt work. If I get the press function out of this makeMove function, it works.
function makeMove(){
// Have a shoot
if(myMove=="T"){
target1.btnHit.onPress = function (){
trace("hit")
}
}
Using Textboxes Inside A Function
I am trying to use a function and inside the function I want to increase a number displayed inside of a textbox.
Code:
function texty(textBox:????) {}
I tried textField and textArea but it says the class cannot be loaded.
help , anyone?
Function Inside Loop
Hi,
I must be doing someting fundamentally wrong but here's my code for calling a function outside of another function.
The problem is that I can't access the i variable in the loop that the function is in. I keep getting the error: TypeError: Error #1010: A term is undefined and has no properties. at MethodInfo-277()
PHP Code:
// function I try to call and pass argument to
function load_db_content(req):void{
trace("url: "+req);
content_bg_mc.visible = true;
var my_request:URLRequest = new URLRequest(req);
var loader:URLLoader = new URLLoader();
var s_vars:URLVariables = new URLVariables();
s_vars.eng = lang;
my_request.data = s_vars;
//my_request.method = URLRequestMethod.GET;
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, load_complete);
loader.load(my_request);
function load_complete(e:Event):void{
var loader:URLLoader = URLLoader(e.target);
content_txt.htmlText = loader.data;
content_txt.visible = true;
my_scrollbar.visible = true;
my_scrollbar.update();
}
}
function set_menu():void{
// loop through menu items
for (var i=0; i <= 5; i++){
// i variable is referencing a multidimensional array, works fine here
this["bg"+[i]].title_txt.textColor = menu_array[i][2];
// single item
this["bg"+[i]].item_btn.addEventListener(MouseEvent.CLICK, temp);
// archive
this["bg"+[i]].archive_btn.addEventListener(MouseEvent.CLICK, temp_a);
// temporary functions because I can't pass an argument from inside an event listener
function temp(e:MouseEvent):void{
// call content loader
}
function temp_a(e:MouseEvent):void{
// here I try to use the i variable but that's not possible from inside this function
trace("param: "+menu_array[i][3]);
//load_db_content(menu_array[i][3]);
}
}
My question is: how can I get the value of the i variable inside the temp_a function? Maybe there is another/better way to do what I'm trying to do?
Hope someone can help. Thank you very much for your time.
AS Function Name Inside XML File
Hi,
can we put function name inside XML so while parsing, we can call a function?
Example
...
<item ref='102667' action='displayTotal();' />
...
then when parsing, find a way to call displayTotal()? So action may content different function name?
If anybody have an idea, it will help me alot!
turb
SetInterval Inside A Function?
Hey guys, just ran into a bit of a snag ... trying to figure out why my code works outside of the main function, but not inside:
Code:
function thumbs():Void
{
var thumb:MovieClip;
thumbArray = new Array();
var duration:Number = 100;
var i:Number = 0;
//for (var i = 0; i < channelCount; i++)
//{
function runThumbs(){
var thumbData:Object = new Object;
deltaX = i - Math.floor(i / thumbsPerRow) * thumbsPerRow;
thumb = chan.attachMovie("c_thumb", "thumb" + i, zIndex++);
thumb._x = deltaX * (thumb._width + xSpacing) + thumbXBegin;
thumb._y = Math.floor(i / thumbsPerRow) * (thumb._height + ySpacing) + thumbYBegin;
thumbData.thumb = thumb;
thumbData.xPos = thumb._x;
thumbData.yPos = thumb._y;
thumbArray.push(thumbData);
thumb.setData(i, channels[i]);
img = "images/"+channels[i].cImg+".jpg";
image_mcl.addListener(imgListener);
image_mcl.loadClip(img, thumb.c_clip);
trace("executeCallback intervalId: " + intervalId + " count: " + i);
clearInterval(intervalId);
if(i < 10) {
i++;
intervalId = setInterval(this, "runThumbs", duration);
}
}
if(intervalId != null) {
clearInterval(intervalId);
}
intervalId = setInterval(this, "runThumbs", duration);
}
thumbs();
so if I take everything outside of the thumbs() function it works fine, but inside ... no go. I'm jsut learning about setinterval ...
oh ... and can someone please let me know what the "this" is inside the setInterval function. I know it's either function or object reference. But I'm still not clear on that part ...
Access A Function That Is Inside Of A Swf From Another Swf
Hi,
I'd access a function that is inside of a swf that is loaded by a Loader. For example:
-I have a function at mundo.swf called : ola();
-I am loading this swf at another swf :
Code:
var urlReq:URLRequest = new URLRequest();
var loader:URLLoader = new URLLoader();
urlReq.url="mundo.swf";
ldr2.load(urlReq);
addChild(ldr2);
- I wanna access this function (I 'm trying:
Code:
var Variavel =MovieClip(ldr2.content);
Variavel.ola();
Thanks!!!!!!!
Function Inside For Loop
I'm having problems with my code and I'm thinking that maybe it is sth to do with the way functions work or do not work when put inside a for loop.
I'm looping through xml data and for every link node I'm making a button and attaching an onRelease action. But for some reason the last link is added to every button. I mean its making the buttons fine except for every button opens the same url which is the url of the last button in the list.
ActionScript Code:
for(var i = 0; i < rootNode.firstChild.childNodes.length; i++) {
var theURL = rootNode.firstChild.childNodes[i].attributes.url;
var Display = rootNode.firstChild.childNodes[i].attributes.displayName;
var item_mc = _root.menu_mc.attachMovie("menu_item","item"+i, i);
item_mc._y = i * item_spacing;
item_mc.url_txt.text = Display;
item_mc.main_btn.onRelease = function()
{
getURL(theURL, "floater");
}
}
Function Inside Loop
I'm trying to assign onRelease functions to a set of 17 buttons using a loop. The actionscript I have at the moment looks like:
ActionScript Code:
for (y=0; y<18; y++) {
gui_news["gui_news_entry_butt_"+y].onRelease = function() {
_root.curr_title = _root.flashData_lv["title"+y];
_root.curr_date = _root.flashData_lv["date"+y];
_root.curr_entry = _root.flashData_lv["entry"+y];
_root.entry_select();
};
}
When I try to do this in the above loop, nothing happens. It works fine if I declare the function outside a loop and increment the numbers manually (For example:
ActionScript Code:
gui_news.gui_news_entry_butt_0.onRelease = function() {
_root.curr_title = _root.flashData_lv.title0;
_root.curr_date = _root.flashData_lv.date0;
_root.curr_entry = _root.flashData_lv.entry0;
_root.entry_select();
};
My question is, is it possible to declare functions inside loops, and if so, what is the syntax for it?
Math Inside Function
I've got a function call that passes a number to the function to be manipulated, for the sake of this question it looks like the following:
function generate_comments(com_num) {
limiter = com_num+1;
com.item_txt.text = limiter;
}
where the passed value "com_num" is equal to 1. Can anyone tell me why, when this function is run, instead of returning the value "2", limiter concatenates 1 and 1 and returns a value of "11"?
As3 Call A Function Inside Swf
I am loading an external swf like that. In the extrnal swf I have a function called "foo". how can I call "foo" function from the main swf?
Thanks
Issue With Var Inside Function
I have a for loop that is adding button functionality to 16 buttons on the stage. It is targeting the button fine with no problem using the var i as the button number. The issue is inside the button function I have another nested button function for the on state of the button which I also use the var i to specify the url number I want associated with the particular button but it is always outputting 17. I don't even understand how it is getting that number. Here is the code.
Attach Code
function gotoURL(movieNum) {
getURL("javascript:flashURL("+movieNum+");");
}
// ----
for (i=0; i<=16; i++) {
this["b"+i].onRelease = function() {
// -- bring selected button to the top deptht
_root.x += 2;
this.swapDepths(_root.x);
// -- defines last selected button and then delete it
var lastBtn:MovieClip;
this._parent.lastBtn.gotoAndPlay(11);
trace("Button Event One");
this.gotoAndPlay(2);
delete this._parent.lastBtn.onPress;
this._parent.lastBtn = this;
updateAfterEvent();
// -- If the user clicks the on state then it goes to some URL
this.onPress = function() {
_root.gotoURL(i);
trace (i);
trace("Button Event two");
updateAfterEvent();
};
};
}
Delay Inside Function
Hi i am trying to make function that loads variables from file and returns them as an array but there is problem i need delay to in this function because variables cannot be loaded so fast as function goes.
the problem is that I need that onLoad executes before return aVariables
can sameon help me?
thanks.
p.s. I use Macromedia Flash Profesional 8
Attach Code
var aSomeArray:Array = getVariables();
function getVariables():Array{
var aVariables:Array = Array();
var lvVariables:LoadVars = new LoadVars();
lvVariables.onLoad = function(bSuccess:Boolean):Void {
if(bSuccess){
var nNr:Number = 0;
for(i in lvVariables){
aVariables[nNr] = lvVariables[i];
nNr++;
};
aVariables.reverse();
var oShifted:Object = aVariables.shift();
};
};
lvVariables.load("test.txt");
return aVariables;
};
Edited: 10/26/2007 at 11:25:20 AM by artishox
Delay Inside Function
Hi i am trying to make function that loads variables from file and returns them as an array but there is problem i need delay to in this function because variables cannot be loaded so fast as function goes.
the problem is that I need that onLoad executes before return aVariables
can sameon help me?
thanks.
p.s. I use Macromedia Flash Profesional 8
Attach Code
var aSomeArray:Array = getVariables();
function getVariables():Void {
var aVariables:Array = Array();
var lvVariables:LoadVars = new LoadVars();
lvVariables.onLoad = function(bSuccess:Boolean):Void {
if(bSuccess){
var nNr:Number = 0;
for(i in lvVariables){
aVariables[nNr] = lvVariables[i];
nNr++;
};
aVariables.reverse();
var oShifted:Object = aVariables.shift();
};
};
lvVariables.load("test.txt");
return aVariables;
};
Function Inside/outside An If Condition
Hi,
I noticed that defining a funciton inside an if condition seems to act
different than one defined before that. I tried to use an setInterval on
a function, both in- and outside the if conditon.
// this one does nothing
if (1){
function globalLoop(){
trace("globalLoop")
}
lv1 = setInterval(globalLoop,100)
}
// this one does loop
function globalLoop(){
trace("globalLoop")
}
if (1){
lv1 = setInterval(globalLoop,100)
}
Where is the difference, how does this behavior explain?
Array Inside A Function
Hi everyone,
I am having a hard time trying to get this to work.
On my main timeline, I create a new array called aEventData:
aEventData = new Array();
On the next frame, I loop through data pulled from ColdFusion. I am trying to put the data into an array so that I can reference it later based on it's position. My function to do this looks like so:
function eventDataQuery_Result ( result ){
// for each record in the recordset...
for (a=0;a<result.getLength();a++){
// Use the record variable to refer to the current row of the recordset
var record = result.getItemAt(a);
//Fill our array with data from the event
_root[aEventData[record.eventDate]] = record.eventDesc;
};
}
This doesn't work. I don't know how to properly reference the array on the timeline. I also tried:
_root[(aEventData[record.eventDate])] = record.eventDesc;
and
_root.aEventData[record.eventDate] = record.eventDesc;
(I knew this one wouldn't work but I had to try.)
If I use aEventData[record.eventDate] = record.eventDesc;
and then trace the value from within my function, it works okay, but it doesn't set the value in the array on my main timeline. Can anyone explain how I can reference and set values in my array from within the function?
Thanks.
[FMX]swapDepths Inside Function
I have a function to fade in and out four movie clips. This is the code:
Code:
function fadeSub(l) {
for (k=0; k<but.length; k++) {
if (k != l) {
this["sub_"+but[k]].onEnterFrame = function() {
this._alpha += (0-this._alpha)/3;
if (this._alpha < 5 ) {
this._alpha = 0;
delete this.onEnterFrame;
}
};
} else {
this["sub_"+but[k]].onEnterFrame = function() {
this._alpha += (99-this._alpha)/12;
if (this._alpha > 98) {
this._alpha = 99;
delete this.onEnterFrame;
}
};
}
}
}
I call the function with:
Code:
clip.onRelease = function() {
fadeSub(this.i);
};
I have buttons inside the sub_mc's that aren't working because of the depths. How doI integrate a swapDepth in the fadeSub function?
Donald
LoadClip Inside The Function()
hello, i´m trying to make a loadClip (by MovieClipLoader) inside a function, but it doesn´t work...and I don´t know why....
please can someone help me?
this is the code that i´m try to use
//to create the class:
var carregador:MovieClipLoader = new MovieClipLoader();
var ouvidor:Object = new Object();
carregador.addListener(ouvidor);
_root.createEmptyMovieClip("alvo",100);
alvo._x = 11
alvo._y = 78
link = "contato.swf"
/*if I put the loadClip action here, the movie clip loads correctly, but I need to use this action inside the function....*/
//to use the loadClip inside the function:
function clipLoader () {
count ++
this.onEnterFrame = function () {
fundoMask._yscale = fundoMask._xscale
fundo._yscale = fundo._xscale
if (fundo._xscale <= 0) {
aciona = true
}
if (aciona) {
fundo._xscale = 20 + (fundo._xscale - 20)/1.2
fundo._alpha = 50 + (fundo._alpha - 50)/1.2
if (fundo._xscale > 19.8) {
carregador.loadClip(link, alvo)
}
ouvidor.onLoadStart = function() {
avisos = "carregando..."
};
trace(_root.alvo.nome2.length)
ouvidor.onLoadInit = function() {
alvo.setMask(fundoMask)
};
ouvidor.onLoadComplete = function() {
//avisos = ""
fundo._alpha +=4
fundo._xscale = tamanho + (fundo._xscale - tamanho)/1.058
if (fundo._xscale > 89) {
fundoMask._xscale = 89 +(fundoMask._xscale - 89)/1.3
}
}
ouvidor.onLoadError = function() {
avisos = "ocorreu algum erro"
};
}
}
}
Function Inside A For Loop
Hey everyone,
I have a function inside a for loop and in that function i am using the counter of the loop (the letter i) as a variable but it seems like inside the function the value of i gets reset.
Here is my code:
siteMenu=["Profile","My work","Links"];
_root.createEmptyMovieClip("mainMC",200);
for(i=0;i<siteMenu.length;i++){
_root.createEmptyMovieClip("MyButton"+i,100+i);
_root["MyButton"+i]._x=100;
_root["MyButton"+i]._y=100+(15*i);
}
_root["MyButton"+i].onRelease=function(){
loadMovie(siteMenu[i]+".swf","mainMC");
}
}
The problem is how can i get around this thing so i can loadMovie according to the value of i.
Thanks for your help guys!
|