ActionScript 2.0 :: Delegate Class - Passing Parameters With Function?
Jan 31, 2008
I am wanted to know how can i pass a parameter to the function which I'm calling using Delegate class. I know to pass params having static values such as true / false or a static string "hello".
Code:
var myFunc:Function = btn.onRelease = Delegate.create(tihs, releaseHandler);
myFunc.str = "hello";
function releaseHandler()
[code]....
Here str can be retrieved as 'arguments.caller.str' inside the function.But in case i want to pass the reference of the 'btn' button. Then how can i do this ?
View 3 Replies
Similar Posts:
Feb 3, 2006
way to say the same in just a few line of code? 25 lines of code people
[AS]menuAS = function () {
//TIOCCHA
menuBar.menu01.menu01_btn.onRelease = function() {
[Code]....
View 6 Replies
Apr 7, 2009
i am loading an image with a loader, and in onComplete function i would like to call calculateRatio function and pass it Loader.content.width and Loader.content.height so it can compare it with the current stage width and height and resize image proporcionally to fit the screen. how would i go about passing that parameters?
[Code]....
View 4 Replies
Mar 4, 2004
{Flash MX 2004 Pro}
[Code]...
The above does not work. Infact the function is not even called. How can I pass parameters to such functions. I dont wanna do the following:
[Code]...
View 1 Replies
Feb 26, 2009
Code:
function enableButtons():void
{
for (var i:uint=0; i<40; i++)
[Code]...
I have 40 buttons on the stage. Their names are contained in the Array musicGrid. What I'm trying to do with this code is attach an EventListener to each button so that it will call the function mgMouseBehavior with a parameter to identify the button. For example, I want the button at musicGrid[0] to call the function mgMouseBehavior(0). I want the button at musicGrid[32] to call the function mgMouseBehavior(32), and so on.
However, if you try to add parameters to mgMouseBehavior in the addEventListener, for example:
Code:
musicGrid[i].addEventListener(MouseEvent.CLICK, mgMouseBehavior(i));
Then you get Error 2007: Parameter listener must be non-null. How would I accomplish what I'm trying to do?
View 2 Replies
Aug 17, 2010
I'm attempting to write a performance testing function that can take any function, run it X times and spit out how long it took that function to run in AS3. I've got it working just fine if a function doesn't take any parameters but it comes up with an error otherwise.Here's the code:
public static function testFunction(targetFunction : Function, object : Object, ... parameters)
{
[code]........
View 1 Replies
Mar 4, 2004
{Flash MX 2004 Pro}
[AS]
myMovieClip_mc.onPress = foo(true);
function foo(state:Boolean) {
Do something
}
The above does not work. Infact the function is not even called.How can I pass parameters to such functions.I dont wanna do the following:
[AS]
myMovieClip_mc.onPress = function(true) {
//
}
View 1 Replies
Jul 23, 2009
Look at the simple code below:
Code:
stage.addEventListener(MouseEvent.CLICK,traceMe);
function traceMe(evt:MouseEvent)
{
trace ("hello world!");
}
What if I want to pass a parameter to the traceMe function? There is a way to do that?
View 2 Replies
May 9, 2009
Consider the function below:
function personal(Name:String,age:int,city:String):void{ trace(Name+" is "+age+ " years old and lives in "+city+ ".")}
The parameters can only(???) be passed in the order they are declared in the function as
[code].....
View 13 Replies
Feb 12, 2010
I've got an XML file that is loading in data and is calling functions.
how to call the methods from classes with variables set from the XML file:
var functionToCall:String = xml.functions.func[0].to_fire.toString();
myClass[functionToCall]();
This calls the function perfectly.
I was wondering if there is anyway to pass parameters into the function as well through variables. Some functions may have no parameters, some functions could have 5... so the xml could be like this:
[Code]....
View 5 Replies
Jul 24, 2011
I have a function at the server side that loads an XML and makes a photo/link array from it.I want to pass this array to the clients swf to use it for a photoGallery.nd the array = [1,2,3,4] to the client and trace it at the client side?
View 1 Replies
Apr 28, 2006
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 frustated with this way of passing multiple parameter which depends on what to pass in flex 2 using addEventListener ?
[URL]
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).
View 9 Replies
Dec 18, 2008
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");
[Code]....
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?
View 1 Replies
Dec 2, 2009
I have benn programming in AS2 for a while, but I'm moving to AS3, and I'm having some trouble with syntax and mostly with management of parameters and variables (actually I tried to work with functions in packages without good results T.T). The game has four different types of shooters, and all of them use the same bullet (shoot function). I have succeeded on disappearing the target (a coin in this case) when it is hit by the bullet, but the problem is that I can't quite find the way to dissapear the bullet properly. I keep receiving this message:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at eco_adm9_fla::MainTimeline/moveBullet()
[code].....
View 3 Replies
Jan 1, 2012
I'm making a function, and I want to pass it's handling less restrictively, kinda like jQuery I guess.
Code:
function cfunc(min, max)
{
return (Math.floor(Math.random()*(max-min))+min);
[Code]....
Now I know that alternately, I could pass them individually to the function and then join them all together as one, but I'd prefer to use one variable and pass the data through it, kinda like a scripting engine.
View 1 Replies
Jun 18, 2009
I have shortened this example to keep it simple, otherwise I wouldnt be doint this
I need to pass different variables to function inForLoop each time.
Code:
function someFunction():void {
for (var i:int = 0; i < columns; i++) {
for (var j:int = 0; j < rows; j++) {
[Code]....
View 3 Replies
Nov 1, 2010
I've got a Vector of ViewToActionMap objects, which have following constructor:
public function ViewToActionMap(_forModule:eModule,
_forAction:eViewAction,
_toFunction:Function,
[code].....
View 1 Replies
Aug 15, 2011
I've got a main.as that loads SWF to the stage. the loaded SWF seppoused to pass a link to the main.as and trigger a javascript function to popUp that photo from that link.
I know there are two ways:
((root as MovieClip).parent.parent as Object).somefunction(parameters);
and to dispatch an event. inorder to pass parameters throug the event i need to extend it with another class.
isnt the (root as... ) more efficient if all i need is to pass a link?
View 7 Replies
Oct 30, 2007
I'm having trouble using the delegate.create method (my first time using it!). Here's part of a class I have...
Code:
public function SiteData(xmlFile:String) {
imagesXML = new XML();
[code]....
View 9 Replies
Sep 16, 2009
I am using a delegate sub-class to perform helper functions for the main app.I have passed all references to it that it needs and it works well apart from the following problem:I also want it to remove an event listener from the main pp.eg:thisStage.removeEventListener(MouseEvent.MOUSE_UP,preOutsideBoundsDragRelease);The compiler tells me I need a reference to "preOutsideBoundsDragRelease" within the removeEventListener statement.eg: "access of undefined property preOutsideBoundsDragRelease
View 1 Replies
Oct 1, 2010
i have a situation like that, and my goal is to access from onRelease either to the class representation and to the onRelease callee (the caller of the release function,that is the movieclip that catch the onRelease event):[code]
View 1 Replies
Mar 26, 2012
I have a sendAndLoad going on in a separate class file and following guides online I've used a Delegate to handle the onLoad part, like this [code]...
View 0 Replies
Jan 31, 2008
I've written a class that will load multiple SWFs and then call a passed function when complete. My problem is that when all the movies have downloaded the passed function won't fire.
[AS]
// LoadChecker
// this class is passed am array and calls a function when all of the objects in the array are loaded
//
[code]....
View 1 Replies
Apr 27, 2011
I keep getting this error #2007 i want to parse the stage and pass a bullet object to a class function that function is called every ENTER_FRAME in the class itself
because the bullet object is added to the stage and on the bullet, there is a event listener to call a function in a class every ENTER_FRAME
but now i want to delete this bullet as it leaves the screen on the top because bullets in this game can only fly upward.
this is some of the code so far in the class itself:
ActionScript Code:
package classes {
import flash.media.Sound;
[Code].....
View 5 Replies
Feb 8, 2006
when I have access to my variables. I have the the follow code:
class Slider {
var myVar = 4;
function Slider () {[code]....
The slider function is being called first to update the myVar value then the findValue function is called. How do I get the find Value function to output 6 ? I want a function that updates the main classes' variable so thet I can use it from any function.
View 1 Replies
Jul 21, 2009
I have a class named Test in Test.as file :
Code:
class Test{
public function set movePlayer(_Playah:MovieClip):Void {
trace(_Playah._x);
[Code]....
and when I "run" this function in my .fla file, its says "undefined" (for this position) how to "pass" MC informations to a function inside a class (x,y coordinates, rotation..) although when I trace only "_Playah" it shows the correct name of MC i've passed to it.
View 2 Replies
Sep 8, 2009
I saw a post that touched on this, but I thought it deserved a thread of its own for explicit verification. It seemed that some of the resident geniuses here had given the thumbs-up to passing your whole doc or app class to a function. Please correct me if I'm wrong, as this sounds convenient but I assumed it would cause heart attacks and CPU meltdowns.
EXAMPLE: Say I have an app class that controls my entire game (or slideshow), and it has an ENTER_FRAME scrolling function that's 50 lines long with tons of conditionals so I want to take it out and make it an external file. I pop it into a new .as file but now all my variables are out of scope. I could pass them each individually, but there are so many it's impractical. So my question is: good or bad practice to pass the entire class?
[Code]...
View 4 Replies
Mar 25, 2010
I want to create a MovieClip, pass this MovieClip to a function in another class where it will be modified.The problem is, when I pass the MovieClip as a parameter to a function and start making changes, the changes are only made locally. The "copy" of the MovieClip inside the function gets changed, but the "real" MovieClip back in my main game class remains unchanged. Here's the code from my Main class:
Code:
var resourceLoader:ExternalResourceLoader = new ExternalResourceLoader();
var myMovieClip:MovieClip;[code].....
View 4 Replies
May 27, 2009
i'm trying to pass variables to another SWF using a Loader/URLVariables combo.
I need to know if this way of passing variables should even work. And if not can some recommend a better way.
var uv:URLVariables = new URLVariables();
uv.lang="en";
uv.gameId="123";
uv.profileId="456";
[Code]...
View 5 Replies
Nov 9, 2010
I need to dynamically pass 2 parameter to an swf movie to make it work properly, they are a number and a boolean. To do this I've changed the html page which contains the movie to php, I pass to the page the parameters' values through GET. The values are correctly passed to the page, I've tried to print them.
I build the call to the swf in this way collpreloader.swf?connid=<?php echo $_GET['connid'] ?>&animazione=<?php echo $_GET['animazione'] ?>
collpreloader.swf correctly reads the connid parameter, but animazione results always true.
[Code]...
View 2 Replies