-
ARGH!...help on multiple arguments for asfunction...
what I want to do is create an array that will allow me to call an SWF, give it x and y coordinates of a blank movie and load into a level...I understand that this will need four arguments...very unsure how to proceed...
can someone give me a quick shot at how I can get started?
Thanks!
-
Senior Member
You can have only one argument in an asfunction. Check asfunction in the flash help files. there is an example how to use it.
- The right of the People to create Flash movies shall not be infringed. -
-
Ah...no
Per Macromedia (whoops!...Adobe )...
Passing multiple function parameters
As mentioned above, the function called by asfunction is only passed a single string argument. One way to mimic passing multiple arguments is to separate the "arguments" using a predetermined string delimiter. Below, three comma-delimited arguments are passed to myFunction.
asfunction:myFunction,argument_1,argument_2,argume nt_3
In the new version of myFunction, the split method is used to break the comma-delimited string into an array of arguments, argumentArray.
function myFunction(param){
argumentArray = new Array;
argumentArray = param.split(",");
for (i=0; i< argumentArray.length; ++i){
trace("Function argument " + i + " = " + argumentArray[i]);
}
}
Testing the movie should result in the following being reported to the Output window:
Function argument 0 = argument_1
Function argument 1 = argument_2
Function argument 2 = argument_3
I'm just not sure how to set up the statement for the asfunction...
-
Senior Member
Yeah you are right I did not think of that possibility. Here is the complete script, but I recommend you not to load into level. you will see why.
PHP Code:
import mx.utils.Delegate;
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("asfunction.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:String = argumentArray[3];
loadMovieNum (argumentArray[0], myLevel);
//
var myLoadedVar:Object = argumentArray[0];
var myListener:Object = new Object ();
myListener.traceVar = setInterval (Delegate.create (this, listener), 1000);
function listener ()
{
if (myLoadedVar != undefined)
{
this["_level" + myLevel]._x = argumentArray[1];
this["_level" + myLevel]._y = argumentArray[2];
clearInterval (myListener.traceVar);
this["_level" + myLevel]._visible = true;
}
}
AsBroadcaster.initialize (myLoadedVar);
myLoadedVar.addListener (myListener);
myLoadedVar.broadcastMessage ("traceVar");
}
And this is the text file.
PHP Code:
test=<a href="asfunction:myTest,testmovie.swf,100,200,1"><font size='24'>Test</font></a>
Here is the modified script for a movieclip loading.
PHP Code:
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("asfunction.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:Number = argumentArray[3];
_root.createEmptyMovieClip ("a", myLevel);
a._lockroot = true;
a.loadMovie (argumentArray[0]);
a._x = argumentArray[1];
a._y = argumentArray[2];
}
Last edited by cancerinform; 06-10-2006 at 12:44 PM.
- The right of the People to create Flash movies shall not be infringed. -
-
Whow!
It works! ..but I don't need the listener/broadcaster code, since it will be calling the SWF to the same main movie...and i wanted to point to an emptymovie, but this might work better...though I'm missing the point about loading into levels...?
BTW, thanks!!!
-
Senior Member
what I want to do is create an array that will allow me to call an SWF, give it x and y coordinates of a blank movie and load into a level.
level
- The right of the People to create Flash movies shall not be infringed. -
-
Cancerinform
it looks like this is going to do the trick...many, many kudos to you!!
-
One last question, if I may...
how can I incorportate this code into the code you provided, so that I can fade the graphic into the stage?...
onEnterFrame = function ()
{
var speed = 2;
if (mc._alpha < 100)
{
mc._alpha += speed;
}
else
{
delete onEnterFrame;
}
};
Thanks again!
-
Senior Member
try this:
PHP Code:
_root.createEmptyMovieClip ("a", myLevel);
a._x = argumentArray[1];
a._y = argumentArray[2];
var mc:MovieClip=_root.a.createEmptyMovieClip ("mc", 1);
mc._lockroot = true;
mc._alpha = 0;
mc.loadMovie (argumentArray[0]);
//
_root.onEnterFrame = function ()
{
var speed:Number = 2;
if (this.mc._alpha < 100)
{
this.mc._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
};
- The right of the People to create Flash movies shall not be infringed. -
-
Senior Member
When I wrote this, I did not have flash. there is a mistake in the script above, Change the script
PHP Code:
_root.onEnterFrame = function ()
{
var speed:Number = 2;
if (mc._alpha < 100)
{
mc._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
};
- The right of the People to create Flash movies shall not be infringed. -
-
Very grateful, but...
I must be missing something...here is the code I'm using in the mainframe...
{
myText.htmlText = "";
};
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("7inch.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:Number = argumentArray[3];
_root.createEmptyMovieClip ("a", myLevel);
a._lockroot = true;
a.loadMovie (argumentArray[0]);
a._x = argumentArray[1];
a._y = argumentArray[2];
}
and here is the link within my 7inch.txt file...
<a href="asfunction:myTest,trtjb.jpg,90,187,1"><font size="10">¢</font></a><br>
I don't see where the code you sent fits in...
-
Senior Member
PHP Code:
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("asfunction.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:Number = argumentArray[3];
_root.createEmptyMovieClip ("a", myLevel);
a._x = argumentArray[1];
a._y = argumentArray[2];
var mc:MovieClip=_root.a.createEmptyMovieClip ("mc", 1);
mc._lockroot = true;
mc._alpha = 0;
mc.loadMovie (argumentArray[0]);
//
_root.onEnterFrame = function ()
{
var speed:Number = 2;
if (mc._alpha < 100)
{
mc._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
};
}
This is the whole script from my example. You just need to adjust the names to your example.
- The right of the People to create Flash movies shall not be infringed. -
-
I'll try...
I'm not much of a coder, more of a graphic designer...
Best!
-
Got It!
figured it out...there was a } missing, but it works great...again, thanks much!
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("7inch.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:Number = argumentArray[3];
_root.createEmptyMovieClip ("a", myLevel);
a._x = argumentArray[1];
a._y = argumentArray[2];
var mc:MovieClip=_root.a.createEmptyMovieClip ("mc", 1);
mc._lockroot = true;
mc._alpha = 0;
mc.loadMovie (argumentArray[0]);
//
_root.onEnterFrame = function ()
{
var speed:Number = 2;
if (mc._alpha < 100)
{
mc._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
};
}
-
A little stuck...
The way I have this set up is that the menu points to a frame (I use a gotoandplay)...I want the movie to disappear when it goes to the new frame...how can I do this with the above code?
As always, thanks!
-
Senior Member
- The right of the People to create Flash movies shall not be infringed. -
-
Movie...
I want to clear the, I believe, mc...the one that is brought in via the alpha script...when I go to another frame, I want to clear it somehow...
-
Senior Member
- The right of the People to create Flash movies shall not be infringed. -
-
Not working...
Here is the actionscript in frame one:
var myLoadvars:LoadVars = new LoadVars ();
myLoadvars.onLoad = function ()
{
myText.htmlText = this.test;
};
myLoadvars.load ("7inch.txt");
//
function myTest (arg1:String)
{
var argumentArray:Array = new Array ();
argumentArray = arg1.split (",");
var myLevel:Number = argumentArray[3];
_root.createEmptyMovieClip ("a", myLevel);
a._x = argumentArray[1];
a._y = argumentArray[2];
var mc:MovieClip=_root.a.createEmptyMovieClip ("mc", 1);
mc._lockroot = true;
mc._alpha = 0;
mc.loadMovie (argumentArray[0]);
//
_root.onEnterFrame = function ()
{
var speed:Number = 8;
if (mc._alpha < 100)
{
mc._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
};
}
stop();
when I click on the asfunction link, it fades the mc in...now the actionscript in frame 2:
mc.unloadMovie();
myLoadvars.load ("bio.txt");
stop();
Does not unload mc...but it does load the bio.txt...HELP?
-
Senior Member
Do some trace actions to see if mc or _root.a.mc or so is undefined or not.
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|