Passing A Function Ref To A Function With Parameters
Can anyone tell me how to pass a function reference to a function WITH parameters?
I want to do something like this:
genericFunc = function(funcRef, params){ //do something that takes a while //and when done... //call my funcRef with params: funcRef(params) } func1 = function(){ //trace("here's funct#1"); } func2 = function(arg1, arg2){ //trace("here's func#2 with arguments "+arg1+" and "+arg2); }
Test 1: genericFunc(func1); Test 2: genericFunc(func2, ...) //this is where I lose it.
So, this works fine if I'm passing in a function call that requires no parameters (test 1). But what I really need to do is keep this flexible so that I can reference different functions with varying numbers of parameters (test 2).
FlashKit > Flash Help > Flash ActionScript
Posted on: 02-06-2004, 02:44 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Function Not Passing Parameters
I have a component on my stage, within this component there is this function at the first frame of the component's timeline:
code: function ContentLoad(File:String, xFile:Number, yFile:Number) {
//Create a container for the image to load into
_root.createEmptyMovieClip("ContentLoader", _root.getNextHighestDepth());
//Load the actual image
_root.ContentLoader._x = xFile;
_root.ContentLoader._y = yFile;
loadMovie("content/location/description.swf", _root.ContentLoader);
}
Inside this same component, there are buttons, which call the function.
This is defined as follows:
code: on (release) {
ContentLoad("description.swf", 100, 100);
}
The function is called, but the parameters aren't passed.
What is wrong ???
Passing Parameters To A Function
Hi,
I'm new to AS3, but have written a piece of code in AS2 which I'm now trying to convert.
Basically I've got a movieclip ("grid1") and in that there are a number of instances of the same movieclip ("g1", "g2" etc) and in that is a textbox ("ans.text"). The code I worte passes the name of the movieclip click and takes the content of that textbox and passes it to a function which checks it.
on the button:
Code:
on (press){
checkAns1p(this.ans.text, this);
}
the function:
Code:
function checkAns1p(myAns, referer) {
if (myAns == sub_answer) {
//do something
}
This works fine, the problem I am finding is now that AS3 does not use "on (press)" I don't see how it's possible to pass this information.
Code:
function checkAns(event:MouseEvent):void {
selectedAns = grid1.g1.ans.text;
if (selectedAns == subAns){
trace("Correct!");
}
}
If I hard code it as above then it works, but I don't want to have to do this 32 times. Is there anyway to pass "this" across as I did in AS2?
[CS3, AS2] Passing A Function (and Its Parameters)
does anyone know how to pass a function, and an unknown number of parameters, through another function? I'd like a function to behave similarly to setInterval, where you pass a function name, and every parameter after the function name, no matter how many there are, is used as a parameter for the function call.
i.e.
function aFunc(bFunc:Function, arg1, arg2, ...):Void
{
// magic code makes stuff happen!!
}
so:
aFunc(bFunc, arg1, arg2, arg3, arg4, arg5);
would give me the same thing as:
bFunc(arg1, arg2, arg3, arg4, arg5);
any ideas?
Passing Parameters To A Function
Hi,
I'm new to AS3, but have written a piece of code in AS2 which I'm now trying to convert.
Basically I've got a movieclip ("grid1") and in that there are a number of instances of the same movieclip ("g1", "g2" etc) and in that is a textbox ("ans.text"). The code I worte passes the name of the movieclip click and takes the content of that textbox and passes it to a function which checks it.
on the button:
Code:
on (press){
checkAns1p(this.ans.text, this);
}
the function:
Code:
function checkAns1p(myAns, referer) {
if (myAns == sub_answer) {
//do something
}
This works fine, the problem I am finding is now that AS3 does not use "on (press)" I don't see how it's possible to pass this information.
Code:
function checkAns(event:MouseEvent):void {
selectedAns = grid1.g1.ans.text;
if (selectedAns == subAns){
trace("Correct!");
}
}
If I hard code it as above then it works, but I don't want to have to do this 32 times. Is there anyway to pass "this" across as I did in AS2?
Passing Parameters Into A Function
Ok gang here's my code:
ActionScript Code:
var rssXML = new XPathDocument();
var blogXML = new XPathDocument();
loadXML(rssXML, parseRSS, "http://mlb.mlb.com/partnerxml/gen/news/rss/col.xml");
//*********************************************************************
import com.xfactorstudio.xml.xpath.*;
//*********************************************************************
function loadXML(obj, func, url) {
trace (obj);
obj.ignoreWhite = true;
obj.onLoad = function(success) {
if (success) {
//trace (obj);
func();
}
};
obj.load(url);
}
What I'd like to do is pass the parameters into the function so that when I first run 'loadXML' the rssXML object loads the proper url and then calls a function entitled 'parseRSS'. The trace is coming up as 'undefined'. Where do my problems lie?
Passing Parameters To A Function
anyone can find a way to say the same in just a few line of code?!
25 lines of code people where are u guys?!
ActionScript Code:
menuAS = function () { //TIOCCHA menuBar.menu01.menu01_btn.onRelease = function() { pageLOADER.loaderIndex.gotoAndStop("menuTioccha"); resetMenu(); menuBar.menu01.menu01_btn._visible = 0; }; //FRANCHINSING menuBar.menu02.menu02_btn.onRelease = function() { pageLOADER.loaderIndex.gotoAndStop("menuFranchising"); resetMenu(); menuBar.menu02.menu02_btn._visible = 0; }; //CATALOG menuBar.menu03.menu03_btn.onRelease = function() { pageLOADER.loaderIndex.gotoAndStop("menuCatalog"); resetMenu(); menuBar.menu03.menu03_btn._visible = 0; }; //STORES menuBar.menu04.menu04_btn.onRelease = function() { pageLOADER.loaderIndex.gotoAndStop("menuStores"); resetMenu(); menuBar.menu04.menu04_btn._visible = 0; }; //CONTACTS menuBar.menu05.menu05_btn.onRelease = function() { pageLOADER.loaderIndex.gotoAndStop("menuContacts"); resetMenu(); menuBar.menu05.menu05_btn._visible = 0; };};
thx
Passing Function Parameters From An XML Doc
Hi-
I'm having an issue with calling a function from an imported XML file. This is my function:
function SwitchImage(movieName) {
this.popBox.popImage.loadMovie(movieName);
this.popBox.popCaption = "Go Bulldogs";
}
This is the XML. The function works fine. It calls the function "SwitchImage" and it loads the image "1.jpg".
<myLife >
<pagetext whatYear="1959">I was born on February 4<a href="asfunction:_global.shell.SwitchImage,images/1.jpg">change picture</a></pagetext>
</myLife>
Now I want to pass it another parameter called "popCaption":
function SwitchImage(movieName, popCaption) {
this.popBox.popImage.loadMovie(movieName);
this.popBox.popCaption = (popCaption);
}
<myLife >
<pagetext whatYear="1959">I was born on February 4<a href="asfunction:_global.shell.SwitchImage,images/1.jpg, my new caption">change picture</a></pagetext>
</myLife>
I'm not sure what I'm doing wrong, but it must be in the XML. Any help is appreciated.
Thanks,
Clemente
Passing Parameters To Function
Hi how can i adjust the code below to pass the variables to the function go()? I not quite sure on how to do it... What i am trying to acheive is that each button will goto a different place, but i want one function to handle it.
CODEimport flash.net.*;
function go (event:MouseEvent) {
//trace(eventObject.name);
var req:URLRequest = new URLRequest(url);
navigateToURL (req, "_self");
}
//b1.addEventListener (MouseEvent.CLICK, go));
b2.addEventListener (MouseEvent.CLICK, go);
//b3.addEventListener (MouseEvent.CLICK, go("#message"));
Passing Function Parameters In A Loop?
Hey guys,
i am creating a flash product catalogue using an xml file to store the data. The catalogue has a few categories and a few products in each category.
I have written the script to put the categories into a array and now I am writing the script to make the category buttons. I want the category buttons to call another function which will place the products from that category on the screen.
The problem is that in the “for Loop” the function parameter is not being set or passed for some reason. Can anyone see what im doing wrong here?
thanks for your help!!!
Joe
PHP Code:
//For loop to place a button instance
for (var i = 0; i <aCat.length; i++) { {
//Place the button instance
attachMovie("mcCatButton", "mcNewCatButton"+i, i, {_x:xPos, _y:yPos});
//add the label
this["mcNewCatButton"+i].catTitle.text = aCat[i][0];
// add an onRelease which calls the displayProducts funciton
this["mcNewCatButton"+i].onRelease = function():Void {
displayProducts(catID[i][1]);
}
// This trace works fine
trace(catID)
}
//This is the function where the products will be displayed on stage
displayProducts function(cat:String) {
// Why does this trace return undefined??
trace(cat)
}
Passing Parameters Of The Function With The Listener
my function is this:
ActionScript Code:
function gotoAndPlayRandomFrameLabel(clip_name, frameLabels_array) {
if (frameLabels_array == undefined) {
frameLabels_array = clip_name.frameLabels;
}
var randomLabel:Number = Math.floor(Math.random() * (frameLabels_array.length));
clip_name.gotoAndPlay(frameLabels_array[randomLabel]);
}
and my timer is this:
ActionScript Code:
var blink_interval:Timer = new Timer(5000);
blink_interval.addEventListener(TimerEvent.TIMER, MovieClip(parent).gotoAndPlayRandomFrameLabel(this.head_mc.blink_mc, this.head_mc.blink_mc.frameLabels));
blink_interval.start();
I'm getting a Error #2007: Parameter listener must be non-null.
How can I pass the parameters with the timer to the function? Make sense?
Passing Parameters To A Function In SetInterval()
If I wanted to set inteval for a function requiring a parameter, how do I
pass the parameter?
If I do like this:
var myInterval =setInterval(f(p),2000);
it causes the functuion to execute immediately
Custom Function, Passing Parameters
If i create a function... function blah(A:MovieClip, B:MovieClip, C:String):Void...
is there a way that when i call it i can pass A and C to it and skip passing B and have the function assign a default value to B? I think i saw that you can do that now in AS3... but i cant find a way to do it in AS2.
so what i want to do is something like blah(A, , C); and somehow only be able to send the first and third parameter if i want.
Thanks!
Kyle
Passing Parameters To A Function In A For Loop
how do i pass the values of a for loop (for example the increment count) to a onRelease function inside that loop? in the example below the movie clip will always go to "whatever.php?var=10" because the value of i when you click it is 10. i want the value of i to be included for each run of the loop. how do i do that? i'm guessing maybe a listener, but i can't get anything to work.
Attach Code
var home:MovieClip = this;
for (i=1; i<10; i++) {
var t = home.attachMovie("myMovie", "myMovie"+i, i);
t.onRelease = function() {
getURL("whatever.php?var="+i);
}
}
Passing Additional Parameters To Function Listeners
hboxvar.addEventListener("mouseDown",dosomething(3 43));
hboxvar.addEventListener("mouseDown",dosomething(1 23));
hboxvar.addEventListener("mouseDown",dosomething(1 2342));
public function dosomething( somenumber:Number ):void {
//do something here
}
I try to do above function but I need to pass variable from hboxvar but not from inside function suggested by macromedia.
any one has the solution?
Thanks in Advance.
any one frustated with this way of passing multiple parameter which depends on what to pass in flex 2 using addEventListener ?
http://livedocs.macromedia.com/labs/...=00000506.html
</mx:Application>Passing additional parameters to function listeners
You can pass additional parameters to function listeners depending on how you add the listeners. If you add a listener with the addEventListener() method, you cannot pass any additional parameters to the listener function, and that listener function can only declare a single argument, the Event object (or one of its subclasses).
Function Call Passing Parameters To PendingCall
Help, I have a situation where I am recieving either one or two parameters from a localConnection call and then I want this reciept to both activate a function while passing that function the parameter. I traced and confirmed that both the receiving localConnection and the sending function are recieving and sending the parameters. My problem is in the pendingCall, the function is not working. If I place a trace before and after the pendingCall statement I see that the call should be recieving parameter,but when I look in the debugger it says that the parameter is undefined. Outlined below is a sample of what I am trying to do.
Code:
//---------------<Sending Test>----------------------\
myBtn.onRelease = function(){
var lcArtInfo:LocalConnection = new LocalConnection();
lcArtInfo.send("_nmGetTest","findfoo", myTxt.text);
trace("sending message to receiving movie "+myTxt.text);
}
//---------------<Sending Test>----------------------\
//---------------<Receiving Test>----------------------\
stop();
import mx.rpc.Responder;
import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall;
import mx.remoting.RecordSet;
import mx.remoting.DataGlue;
import mx.styles.CSSStyleDeclaration;
import mx.data.binding.*;
//--------------< This is forms interactive basics for the frontpage search>----------\
var artest_lc:LocalConnection = new LocalConnection();
artest_lc.findfoo= function(param1:Number):Void{
trace("Receiving movie is receiving from sending movie this: "+param1);
getAPic(param1);
};
artest_lc.connect("_nmGetTest");
mx.remoting.debug.NetDebug.initialize(); // initialize the NetConnection Debugger
var myLogger:Log = new Log( Log.DEBUG, "logger" );
myLogger.onLog = function( message:String ):Void {
trace( "myLogger-->>>"+message );
}
makeCall = new Service(
"http://localhost:8080/netstore/gateway",
null,
"com.nm.java",
null,
null);
function getAPic(param1):Void {
trace("param1 = "+param1);
var pt_pc:PendingCall = makeCall.getAllAAs(param1);
pt_pc.responder = new RelayResponder(this, "ads_Result", "ads_Fault" );
};
//---------------<Receiving Test>----------------------\
Thanks in advance for any assistance you can provide.
Passing Additional Parameters To Function Listeners
Hello all,
I'm aware that this topic has been covered before, but after several hours googling and experimenting, I'm not getting any closer and could really do with some help.
I'm migrating to from AS2 to AS3 and trying to get my head around best practices using listeners on buttons.
Let's say I have ten buttons which I've created on my stage in the Flash IDE (these are instances of SimpleButton) which are labelled :
myBtn1
myBtn2
myBtn3
.....
myBtn10
What I want to do is make a function that is called when each one is clicked on which has a parameter passed depending on which one was clicked.
In AS2, I used to achieve this by using Joey Lott's Proxy.as class as follows:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].onRelease = Proxy.create (this, doStuff, i);
};
private function doStuff (i:Number) : void
{
trace("Hey look! Button number "+i+" just got pressed!");
}
Now, obviously in AS3 I guess should be using Listeners instead, so I'm doing something like this:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].addEventListener( MouseEvent.MOUSE_UP, doStuff );
};
private function doStuff (e:MouseEvent) : void
{
trace("Hey look! A button got pressed!");
trace("I know I can find it's instance name by using "+e.currentTarget);
trace("But that doesn't really help me.");
}
Using the above, I know I could stick a switch statement inside my doStuff function and use e.currentTarget to get the instance name of the button that was pressed and work out what to do that way, but that would be an awfully long-winded way of doing it.
From all the googling I've been doing on the subject, it seems I should be creating a custom Listener, but despite finding a few relevant board posts:
http://www.actionscript.org/forums/a.../t-104284.html
http://board.flashkit.com/board/show...event+listener
http://www.actionscript.org/forums/s...ters+listeners
...I can't seem to get them working for the life of me, and I'm totally stuck as to what approach I should really be taking.
Another approach would be to make all my buttons movieclips instead of SimpleButtons and then to add the parameters like this:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].myFunkyParameter = i;
this["myBtn"+i].addEventListener( MouseEvent.MOUSE_UP, doStuff );
};
private function doStuff (e:MouseEvent) : void
{
trace("Hey look! A button got pressed!");
trace("And the parameter is: "+e.currentTarget.myFunkyParameter);
}
... but it seems that you can't add variables to SimpleButtons and I'm loathe to stop using Button-type symbols as I do find them very handy for doing quick rollovers, specifying hitAreas etc.
So can anyone help me?
Thanks!
Passing Additional Parameters To Function Listeners
I have already created a custom mouse event which seems to work fine. It is simply a mouse event which passes an additional sound object. The problem is I am passing this event to another class which checks for collision of a movie clip with another and if true it adds the sound to an array. What I think is happening is a type conversion problem between my customEvent and the MouseEvent.
Error (1119: Access of possibly undefined property sound through a reference with static type flash.events:MouseEvent.
Thanks
Frame Code
ActionScript Code:
this.drum1.addEventListener(MouseEvent.MOUSE_DOWN, newDrums);
function newDrums(event:MouseEvent):void{
var drum:drumKit = new drumKit();
addChild(drum);
drum.x = 200;
drum.y = 200;
dispatchEvent(new CustomSoundEvent( MouseEvent.MOUSE_UP, sound));
drum.addEventListener(CustomSoundEvent.MOUSE_UP, checkTarget);
}
function checkTarget(event:MouseEvent):void {
timeline1.checkTarget(event);
}
Timeline Class
ActionScript Code:
public function checkTarget(event:MouseEvent):void {
for (var i:int = 0; i < _timeBlocks.length; i++) {
var currentX:Number = event.currentTarget.x;
var currentY:Number = event.currentTarget.y;
if (event.currentTarget.hitTestObject(_timeBlocks[i])) {
event.currentTarget.x = _timeBlocks[i].x;
event.currentTarget.y = _timeBlocks[i].y;
event.currentTarget.disable();
addtoTimeline(event.sound);
}
}
}
Custom Event Class
ActionScript Code:
package {
import flash.media.Sound;
import flash.events.*;
public class CustomSoundEvent extends Event {
public static const MOUSE_UP:String = "mouseUp";
public var sound:Sound;
public function CustomSoundEvent( type:String, s:Sound ) {
this.sound = s;
super( type );
}
}
}
Irrelevant code omitted
Passing Additional Parameters To Function Listeners
Hello all,
I'm aware that this topic has been covered before, but after several hours googling and experimenting, I'm not getting any closer and could really do with some help.
I'm migrating to from AS2 to AS3 and trying to get my head around best practices using listeners on buttons.
Let's say I have ten buttons which I've created on my stage in the Flash IDE (these are instances of SimpleButton) which are labelled :
myBtn1
myBtn2
myBtn3
.....
myBtn10
What I want to do is make a function that is called when each one is clicked on which has a parameter passed depending on which one was clicked.
In AS2, I used to achieve this by using Joey Lott's Proxy.as class as follows:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].onRelease = Proxy.create (this, doStuff, i);
};
private function doStuff (i:Number) : void
{
trace("Hey look! Button number "+i+" just got pressed!");
}
Now, obviously in AS3 I guess should be using Listeners instead, so I'm doing something like this:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].addEventListener( MouseEvent.MOUSE_UP, doStuff );
};
private function doStuff (e:MouseEvent) : void
{
trace("Hey look! A button got pressed!");
trace("I know I can find it's instance name by using "+e.currentTarget);
trace("But that doesn't really help me.");
}
Using the above, I know I could stick a switch statement inside my doStuff function and use e.currentTarget to get the instance name of the button that was pressed and work out what to do that way, but that would be an awfully long-winded way of doing it.
From all the googling I've been doing on the subject, it seems I should be creating a custom Listener, but despite finding a few relevant board posts:
http://www.actionscript.org/forums/a.../t-104284.html
http://board.flashkit.com/board/show...event+listener
http://www.actionscript.org/forums/s...ters+listeners
...I can't seem to get them working for the life of me, and I'm totally stuck as to what approach I should really be taking.
Another approach would be to make all my buttons movieclips instead of SimpleButtons and then to add the parameters like this:
Code:
for ( var i=1; i<=10; i++ ) {
this["myBtn"+i].myFunkyParameter = i;
this["myBtn"+i].addEventListener( MouseEvent.MOUSE_UP, doStuff );
};
private function doStuff (e:MouseEvent) : void
{
trace("Hey look! A button got pressed!");
trace("And the parameter is: "+e.currentTarget.myFunkyParameter);
}
... but it seems that you can't add variables to SimpleButtons and I'm loathe to stop using Button-type symbols as I do find them very handy for doing quick rollovers, specifying hitAreas etc.
So can anyone help me?
Thanks!
[AS 2.0] Passing Parameters From A Cue Point To Listener Function
I have an FLVPlayback component with several ActionScript cue points designated along its timeline. I've written a listener that successfully executes a function whenever the video reaches one of my cue points. However, I'd like it to do different things depending on which of the cue points it has reached.
Here is my code:
Code:
// these are the cue points that I'm adding to my video
_root.thevid.addASCuePoint(33, "show1");
_root.thevid.addASCuePoint(43, "hide1");
_root.thevid.addASCuePoint(63, "show2");
_root.thevid.addASCuePoint(73, "hide2");
_root.thevid.addASCuePoint(93, "show3");
_root.thevid.addASCuePoint(103, "hide3");
var listening:Object = new Object();
listening.cuePoint = function():Void {
// code
}
_root.thevid.addEventListener("cuePoint", listening);
Essentially, I would like for the function to accept a String name from the cue point, and then decide which action to take (either showing or hiding something). I don't know the correct syntax for accepting information from the cue point. Should I pass the cue point into the function as an object, then parse its name from within the function?
Every example I've seen dealing with cue points and listeners has assumed that I only want one type of action to occur when a cue point is encountered - which is not the case.
Passing ...rest To A Function With An Undefined Number Of Parameters
So, let's say I am passing a function and its parameters to another function:
[as]function caller(func:Function, ...params) {/as]
So I want to call the function that's been passed, using params as the parameters. But if I just do this:
ActionScript Code:
func(params);
then it calls the function with one parameter, which is an array of parameters.
I could try something like this:
ActionScript Code:
switch (params.length) {
case 0:func();break;
case 1:func(params[0]);break;
case 2:func(params[0],params[1]);break;
case 3:func(params[0],params[1],params[2]);break;
...
}
But that seems a poor way to do it, and will eventually hit an upper limit on the number of parameters that can be passed.
Calling A Function From An Html Link And Passing Multiple Parameters
Hi all
Okay I know how to call a function using an html link like this:
Code:
<a href="asfunction:_root.DoThis,Parameter">Click here</a>
my problem is I need to pass in several parameters but when I do this:
Code:
<a href="asfunction:_root.DoThis,Parameter1,Parameter2,Parameter3">Click here</a>
it passes one parameter with this value:
'Parameter1,Parameter2,Parameter3'
Does anyone know how I get round this?
Thanks in advance
Pass Function Parameters In Another Function
Hi guys!
I have a timer and I want to call a function once the interval I set expires, pretty standard.
But when I also want to pass a couple of extra arguments with the Timer parameters.
Code:
var timer:Timer = new Timer(500, 10);
var X:Number = 10;
timer.addEventListener(TimerEvent.TIMER, notifier[pass extra args here]);
// now I want to send this number X to the notifier function.
function notifier(event:TimerEvent, var total:Number = 0):void {
trace(timer.currentCount);
trace ("total: " + total);
}
timer.start();
This is only a snippet. I want to know how I'm to pass the extra arguments to the function.
Thanks in advance!
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
Code:
package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
Code:
import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
Code:
package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
// var loader:URLLoader = URLLoader( event.target );
// trace( "Par: " + loader.data.par );
// trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
Code:
import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
Mysql->PHP->FLASH Function. (Passing Function To A Package)
I've just started with ActionScript3.0, and is currently working on a flash that is to communicate with a mysql database and have found a great deal of example code online that I've started to work with.
Currently I have the following package added to my project:
quote:package
{
import flash.events.*;
import flash.net.*;
public class SendAndLoad
{
public function SendAndLoad()
{}
public function sendData( url:String, _vars:URLVariables, completeFunc:Function ):void
{
var request:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener( Event.COMPLETE, completeFunc );
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
loader.load(request);
}
//private function handleComplete( event:Event ):void
//{
//var loader:URLLoader = URLLoader( event.target );
//trace( "Par: " + loader.data.par );
//trace( "Message: " + loader.data.msg );
//}
private function onIOError(event:IOErrorEvent):void
{
trace("Error loading URL.");
}
}
}
And is running the following code in my flash:
quote:import SendAndLoad;
import flash.net.URLVariables;
function loadUsername( event:Event ):void
{
var loader:URLLoader = URLLoader( event.target );
//userNameText.text = "ffff";
userNameText.text = loader.data.user;
}
var url:String = "pages/test.php";
var vars:URLVariables = new URLVariables();
var sal:SendAndLoad = new SendAndLoad();
sal.sendData( url, vars, loadUsername );
As you can see I am trying to seperate the function to be called when the return value of the page I am accessing returns with a value, so I wont need to pass all different actions to be called on different pages I will be requesting throughout my flash program.
But as it is now, the function loadUsername, never even gets called, which I assume is because the package can't call the function outside it.
As I said, I am just starting out with ActionScript 3.0, and is kind of stuck at this.
Any thoughts?
Edited: 10/09/2008 at 08:46:50 AM by _TT_
Passing A Function To Another Function In A Loaded Swf
Here is the problem: to make it simple, I have two swf's, one loaded into a movie instance of another swf. In the loaded swf, there is a function called checkClient with a variable passed into the function. Here is the code for checkClient
function checkClient(userID)
{
_parent.isResultCompleted(checkClient(userID));
}
isResultCompleted is a function in the root swf with the code
function isResultCompleted(functionToBeChecked)
{
functionToBeChecked;
}//end function check result
The problem I'm having is that functionToBeChecked dosen't call the function checkClient. The code in red is where I know the problem lies. Any ideas?
I have been trying to get this to work for a while now and have looked all over this forum, but nothing seems to give me a result that works. Thanks in advance. KD
Passing A Function Handle To A Function...
How can I do the following:
So I add a new child to my stage and inside this movie I got a couple variables and button handling lines of code.
I set this variables on each of the created movies and I would like to also pass a reference to a function.
This reference function can than be called when a button is pressed inside any of those created movies on my stage...
//Pseudo code
this.clip34.setFunctionReference(displayMessage);//Here I pass my function handle... How can I do this?
function displayMessage(str:String)
{
trace(str);
}
function setFunctionReference(func:FUNCTION?)
{
func("Hey I was clicked!");
}
Hope you understand me... ^.^
Function Parameters
Can anyone tell me why this code is incorrect? I should be able to assign the elements of variable parseNum as a parameter for the function navColorVal() but it only works when I list each element of the array like navColorVal(convert[0],convert[1],convert[3],etc.....)
Can someone explain?
Code:
function setUpNavBar() {
_root.loadVariables("/somescript/api.jsp?action=getProperties&group=unit");
convert = unescape(_root.navColor).split(",");
for (i=0;i<convert.length;i++) {
parseInt(convert[i]);
}
parseNum = convert.concat();
_level13.navHolder.colorString=convert.concat();
navColorVal(parseNum]);
}
[Edited by Dionysys on 08-13-2002 at 05:31 PM]
Using Parameters In A Function
I am trying to use the same functions with different dynamic text boxes. i.e. I am making the text box blink. I have now added a second dynamic text box to my flash file and want to use the same functions with both text boxes. I would like to know how to pass the instance name as an argument or parameter to these functions. I having trouble with this and keep getting undefined parameters as they were being passed through. So I removed them to prove to myself that the functions are still working. Could someone fix my flash file for me or guide me to some documentation on passing instance names?
Thanks,
NT
Using Parameters In A Function
I am trying to use the same functions with different dynamic text boxes. i.e. I am making the text box blink. I have now added a second dynamic text box to my flash file and want to use the same functions with both text boxes. I would like to know how to pass the instance name as an argument or parameter to these functions. I having trouble with this and keep getting undefined parameters as they were being passed through. So I removed them to prove to myself that the functions are still working. Could someone fix my flash file for me or guide me to some documentation on passing instance names?
Thanks,
NT
Function Parameters
Hi there,
I was just wondering if someone could explain something to me as i have never understood it.
In colins book its got
function say (msg) { // Define the msg parameter
trace("The message is " + msg); // Use msg within the trace( ) statement
}
I understand functions to an extent but not perameters. There is no variables before hand this is just the code but all i get is "the message is undifined".
So could someone point out an example of something simple to explain, not //comments but just as if you were explaining it to your mum.
"The fuction is called say...."
Function Parameters
hi .. again with functions.... :s
I've this:
cursos[c].addEventListener(MouseEvent.CLICK, mostraHorario(c);
cursos is an array, that read values from XML.. that creates a list (text fields that allows to click)..
when clicked i want to invoke the function mostraHorario... and parse the value from var 'c'....
so next to it, i have this too:
function mostraHorario(Event:MouseEvent, i:int) {
....
}
but it don't works....
question: how can i parse the value c into the function??
i tried very solutions and all of them retrive errors (syntax, or mismatch number of arguments,...)
help me again...
thanks.
Function With Parameters
it is part of a class)
In interfaz.as
ActionScript Code:
public function sgtePantalla(_stage)
{
_stage.btn_ant.alpha = 1;
this.pantallaActual++;
}
In the main.fla
ActionScript Code:
btn_sgte.addEventListener(MouseEvent.CLICK,interfazVit.sgtePantalla(this));
Show this Error
Parameter listener must be non-null.
Thanks !!
Function Parameters
Hey all...
I am building a flash site for a client and i have come across the following problem.
I have the following script a keyframe of a swf that is loaded by a "nest" movie.
ActionScript Code:
media_actions = function() { media.contents.onRelease = function() { _root.media01.swapDepths(100); }; media.contents.onRollOver = function() { _root.media01.media.contents._alpha = 100; }; media.contents.onRollOut = function() { _root.media01.media.contents._alpha = 30; };}
So this code is meant to be a somewhat elaborate button for the movie that contains it. That is to say, this is code that is living in the movie "media01".
I am looking at building somehting like 25 itterations of these clips, and they all have roughly the same code instructions, so i just want to build a global function that can be reffered to with a simple media_actions(); call and BOOM, no need to re-write the script.
But here is the problem. I have built the function as you can see, but when i assign a parameter to the function so that the parameter is what defines the media number, and then when i have a function call to the effect of
media_actions(media01);
Flash cannot seem to figure out what i am talking about.
I suspect this is retardo simple, and i will be slapping my head shortly.
Cheers Doods!
Function With Parameters
I have this function (it is part of a class)
In interfaz.as
PHP Code:
public function sgtePantalla(_stage)
{
_stage.btn_ant.alpha = 1;
this.pantallaActual++;
}
In the main.fla
PHP Code:
btn_sgte.addEventListener(MouseEvent.CLICK,interfazVit.sgtePantalla(this));
Show this Error
Parameter listener must be non-null.
Thanks !!
Function Parameters
Would someone be able to either explain, or point me to some good reading, on Function Parameters. I feel like it is a big part of AS and something I truly don't understand. I have seen it being used, but can't figure out why. Anyone that can use English, and maybe even a silly example, it would be greatly appreciated!
So I know I am requesting the right thing...
Code:
function myFunction(what is this for??)
Thanks to all!
Checking Parameters In A Function
Hi All,
Just a quick on, is there any way to dynamically check how many parameters have been passed to a function without declaring them in the function header. so:
I am presently doing something like this for a prototype function"
function f_whatever (item1,item2,item3,item){
trace ("blah blah");
}
then called with
f_whatever("red", "green", "yellow");
what I want to be able to do is use the same call to the function but not have to list item1, item2, item3 etc in the function header, but instead just check how many there are at run time.
This is because the amount of items could become quite large and as such I dont want to type them all out.
Hope someone can help, cheers.
Rowdy
Arrays Used As Function Parameters
Hello
I am trying to use a function with four parameters x,y,xscale,yscale. these values are stored in a 2D array. I am having problems getting it to work though and was wandering if anyone had any clues as to what might be wrong.
This is the Array:
map = new Array ();
map[0] = "";
map[1] = new Array(200, 0, 100, 100);
map[2] = new Array(350,250,250,250);
This is the function:
function mapzoom (x,y,xscale,yscale) {
isomxb = x;
isomyb = y;
isomxscb = xscale;
isomyscb = yscale;
mcFall.gotoAndPlay(1);
mcFall.movie = "isom";
trace (x);
}
and this is the array call:
on (press) {
_parent.menu("mcDDMTV");
_parent.mapzoom(map[1]);
}
The call is made from a button in a movie clip, on the main timeline. Thanks a lot for any help.
Sam
Function Parameters - Need Expert Help
right i have read colin moocks chapter on functions and parameters and i still cant understand how to use parameters in functions.
lets say i want a function that randomly moves a named movieclip on the stage.
example code in first frame on main timeline:
//this is where i am attempting to declare my function with its parameters
function sample (a_name,xpos,ypos){
_root.a_name._x=xpos;
_root.a_name._y=ypos;
}
code in a button action:
//this is where i am attempting to use my sample function with a button to move the ball MC to a random position.
on (release){
a=random(300);
b=random(200);
sample(ball,a,b);
}
what am i doing wrong, i am no stranger to actionscript, but this ones really doing my head in. i know this might be a simple solution, but its a very illusive one please help! thanking you in advance.
Function Parameters And SetTextFormat...
im trying to create a function that sets the TextFormat of a textbox when a button is pressed. I want to make my function have only one parameter that is plugged into the path for the textbox...
let me just show the code
this is my function now
Code:
shellName = orangeShell;
txtName = orangetxt;
formatName = orangeFormat;
setFormat(shellName,txtName,formatName){
_root.home.shellName.txtName.setTextFormat(formatName);
}
this is what i want to work...
Code:
hue = orange;
setFormat(hue){
_root.home.hueShell.huetxt.setTextFormat(hueFormat);
}
i just want it to plug in orange (or whatever color i put), wherever it says hue...
How To Pass Parameters To Such Function?
Hi,
See the following code
function myFunc(para1){
_root.val = para1;
}
btn1.onRelease = myFunc ///How to send the parameter to the function???
In above example, how should I send the parameter to the function?
Function Parameters - No Affect ?
Hi all.
Umm confusing problemo....
Ive got a function on FRAME1 that loads a a text file in a dynamic txt to a MC on stage.
In the subsequent FRAMES I've set the parameters of this function to pick different texts.
Well after the first pick-up the function dose'nt work.
I've tried deleting the dyn txt entries from the next button trigger, but no success.
THE CODE:
ON FRAME 1:
function loader (mainTextFile) {
loadVariables (mainTextFile+".txt",mainMc);
}
ON FRAME 2:
_root.loader("aq");//aq is the first text file
ON FRAME 3:
_root.loader("sw");//sw is the second text file
Any sol anybody?? Appreciate it.
A Function's Parameters And Tracing
I am trying to make it possible for the user to customize the controls on a game I am creating.
_root.stageWindow.loader.magus.keyLEFT is the actual keyCode (default is 65, or A)
keyNames[] is an array that assigns all of the keyCode numbers a string that would indicate to the user what the key is (ie keyNames[65] = "A";)
_root.txt_keyLEFT.text is a dynamic text field that displays the key name.
loader is an empty movie clip that another swf (just the character that is controlled) is loaded on.
Code:
function keyInput(action){
inputKeyListener = new Object();
Key.addListener(inputKeyListener);
inputKeyListener.onKeyDown = function(){
if(action == LEFT){
_root.stageWindow.loader.magus.keyLEFT = Key.getCode();
_root.txt_keyLEFT.text = keyNames[_root.stageWindow.loader.magus.keyLEFT.toString()];
trace(_root.stageWindow.loader.magus.keyLEFT);
}
Key.removeListener(inputKeyListener);
}
}
There is an if statement for each action (left, right, duck, up, jump, attack, cast, run, and eventually a few more), but I didn't add those to help the simplicity. Next to each text field I have a button with the corresponding code that would launch the function (for left, keyInput(LEFT);)
Trouble is it launches each if statement as though they are all satisfied. That couldn't have been right, so I tried to trace(action); and it came up undefined.
Code:
function keyInput(action){
trace(action);
inputKeyListener = new Object();
So, why are all of the if statements being satisfied when they shouldn't be?
Variables From Function Parameters?
(Flash MX 2004 Pro)
Okay, so I'm calling an actionscript function from an HTML file, that I called displayImage (guess what it does!).
here is the function:
Code:
function displayImage(imageName){
_root.introMovie.siteMovie.imageName._visible=1;
}
and I call it from the HTML using this code:
Code:
<a HREF="asfunction:displayImage,image1">
unfortunately, this does not work properly. image1 does not become visible, so Flash doesn't like how I use the name to call its instance.
obviously, I have a movieClip object located in _root.introMovie.siteMovie called image1. actually, everything works fine when I hard code it as such:
Code:
function displayImage( ){
_root.introMovie.siteMovie.image1._visible=1;
}
...that is, when I use the exact movieClip instance name directly in the function, it works. My image shows up when I click that link, and it looks beautiful.
but silly overzealous me, I want to make this function reuseable, and not have to write a new one for every image i want to include. so can someone please tell me how to go about using my parameter of "imageName" to act as the instance name of a movieClip object somewhere on my timeline?
I've tried passing in the parameter in quotes (i.e. as a string?), using the object.toString() method, etc etc. Nothing has worked for me so far.
I would really appreciate some help on this one!
Thanks,
Alex
Parameters In A LoadMovie Function....possible?
I'm using an extension called Active Photo Viewer (it zooms in and pans on a photo) and I'm wondering if it's possible to get it to do something. It consists of an .swf which, when published, includes the following parameter:
<,param name="flashvars" value="image=photos/green_bedroom.jpg&maxZoom=200¢erpoint=3¢er Color=0x000000&nav=true&navColor=0x666666" />
and there's also this line of code:
<,embed src="ActivePhotoViewer.swf" id="Westwoodgreenbedroom" quality="best" flashvars="image=photos/green_bedroom.jpg&maxZoom=200¢erpoint=3¢er Color=0x000000&nav=true&navColor=0x666666" scale="noscale" bgcolor="#FFFFFF" type="application/x-shockwave-flash" width="550" height="550" pluginspage="http://www.macromedia.com/go/getflashplayer" />
There's more, but those are the lines that communicate the specifics of what I want active photo viewer to do.
Right now, I have the zoom function opening in a new window, but I'd like to call the .swf using the LoadMovie command and have it embedded in the page. Is there a way to communicate the info in the above code using actionscript?
If not, does anyone know of a nice Zoom extension that would permit me to embed the image being zoomed in on into an existing movie?
You can see what I'm trying to do here - just click the second thumbnail from the top on the left photo bar ("living room"), then click "zoom" below the enlarged photo...
http://www.wywalk.com/PEEL/deluxe_te.../template2.htm
Thanks for any suggestions!
Adding Function Parameters
having a little trouble. this was working previously, before I tried adding parameters to the function. previously, I determined whether "this" in bulletMove was a bullet or a charge by the scale of the movie clip (the charge was 51 while the bullet was 100). Trying to make the code more intuitive, I've decided to pass a boolean to the function instead. Now, when bulletMove is called, every reference to "this" in the function seems to refer to the entire screen rather than just the charge or the bullet, because the whole screen starts rotating with each release of the spacebar.
charge_mc.onEnterFrame = bulletMove(false);
bullet_mc.onEnterFrame = bulletMove(true);
/*the previous two function calls are located within an onKeyUp function for spacebar, if that makes any difference...*/
function bulletMove(bulletnotcharge) {
if (!bulletnotcharge)
this._rotation++;
}
help?
[F8] Function Parameters From String?
I have this function that should take the parameters and exec a function:
code:
function execEvent(myparam:String)
{
if (myparam != "")
{
var miniarray = new Array;
miniarray = myparam.split(",");
var parameters = ""
if (miniarray.length > 1)
{
for (var z=1;z<=miniarray.length-1;z++)
{
parameters += miniarray[z] + ","
}
parameters = parameters.substring(0,parameters.length-1);
}
if (parameters != "")
_root[miniarray[0]](parameters);
else
_root[miniarray[0]]();
}
}
Then I have a function:
code:
function MyFunction (mypar1,mypar2,mypar3)
{
trace (mypar1);
trace (mypar2);
trace (mypar3);
}
Then when I run:
execEvent ("MyFunction,joe,mary,peter);
Well, I think I should get:
joe
mary
peter
But I get:
joe,mary,peter
undefined
undefined
Any clues how to tell Flash that they are separated parameters?
Modifying Function Parameters
I'm building a function (maskMove) to control five loaders. Loader1 animating then loader2 and so on. The function is organizaed as follows:
maskMove = function (loader_mc, ystart, yhome, target_mc) {
xmove = [equation]; //calcuates far to move the loader to move
if (loader_mc._y > yhome) { // download incomplete
loader_mc._y = [equation]; // moves the _y location (animates)
}
else {
// once loader1 is complete maskMove should continue to run, but hold new parameter values (the values for each loader are listed below)
}
}
maskMoveExecute = setInterval (maskMove, 50, _root.loader1_mc, 240, 47, _root.content1);
List of parameters associated with each of the five loaders:
loader1 (_root.loader1_mc, 240, 47, _root.content1)
loader2 (_root.loader2_mc, 168, 26, _root.content2)
loader3 (_root.loader3_mc, 220, 26, _root.content3)
loader4 (_root.loader4_mc, 200, 26, _root.content4)
loader5 (_root.loader5_mc, 125, 26, _root.content5)
I have a couple ideas of how to make this functional, but am hoping to gather insight to decide with it's the most effective method. I was either thinking of using variables or functions.
[CS3 AS2] Get Identifier From Function Parameters
Is there a way to pass the identifier from function parameters into a variable?
What I have is:
PHP Code:
function test(param) {
trace(param.x); // outputs 2
}
test({x:2, y:4});
From this example, of course, I can get the number, but if I want to get the indentifier "x"...how can I do this?
Thank you!
|