ActionScript 3.0 :: Functions Embedded Inside Other Functions?
Jan 14, 2011
Functions embedded inside other functions? In all my years of ActionScript programming, I've never seen this (this is part of legacy code written by someone else which I am adapting):
I have a series of calculations i'm doing over a bunch of objects stored in a array. Each function is pretty CPU demanding but if you only run one function, it just works fine.
I've got a project thats getting a bit big, so Im taking the actionscript out into separate as files. I want all the basic functions to be in BasicFunctions.as and the make a library for more specific functions. I find that a lot of people use the import statement but I cant get that to work with a simple Hello World trace, yet the include statement works fine (see attached). I understand that import/include work differently, but which is the better method? If import, then is that heavier to work with. Any rate, what's the best way to organise code when it gets to the 1000+ lines?
I am embedding a number of SWFs in my main Flash movie, and I need to call functions within those SWFs.This is no problem when loading the SWF as an external file, but when I use the [embed] directive to embed the SWF directly into my app there seems to be no way to access the functions?I tried numerous approaches, including waiting for the embedded SWF to be added to the stage, but it seems it just does not allow access. And unfortunately in my case, loading the SWFs separately is not a good solution.
I'm trying to find a way to have global functions in my as project, similar to how flash does with stuff like the util functions (describeType()...), where you can just call the function wherever you need it. For example:
[Code]...
So when I call Test(), it prints out "hello world" fine. My problem comes in that I can't change the name of the Test function, and I can't add any other functions without compiler errors. Is it possible to have a load of global functions in one file, or do I have to split them up into separate files like in the example? Also, I know that I can make a Global class and call static functions like Code: Global.doSomething() but I'd like to know if there's a way to do it as flash does it (describeType(), getDefinitionByName(), etc), or rather, how does flash do it?
I have one function that puts text in a text field and makes a button goto a url onRelease.The code is like this:
Code: item.onRelease = function() { myButton.onRelease = function() { getURL("http://google.com", "_blank"); } talk = this.txt; } the only problem is that the button doesn't work onRelease. i think that it is because there are too many functions there, but at the same time,
Its a complicated senario for me. I have a sound management singleton with an asset like dictionary storing all referances to my urls and assets and the guff inside it-
I have a function called addItem(id:String, url:String):Object
I would love to do something similar as soundManager.addItem(id:String, url:String).play() or soundManager.addItem(id:String, url:String).stop() of which it'll both add my item to my dictionary, and begin playing the sound
Let's I have a class Square that has a several functions. I want to call it from a class Grid, which is a group of Squares.So in the class file for Grid, how would I do this:
Code: public function doSquareFunction(thisFunction:Function):void{ square1.thisFunction();
I have a function with 4 necessary arguments (aka parameters) in order to perform the actions. I would like to have the ability to pass the same function to itself as an argument (sort of like a recursive function) along with its arguments. Basically I want to "base" to engage an onMotionFinished event handler if there is another function passed as an argument. Something like...
[Code].....
Would there be a way to use listeners to do this or the AsBroadcaster?
ActionScript Code: //links var navBarButtonArray:Array = new Array(navBar_mc.gadgetNews_btn, navBar_mc.gadgetReviews_btn, navBar_mc.gadgetFeatures_btn, navBar_mc.iphoneNews_btn, navBar_mc.androidNews_btn); var categoryArray:Array = new Array("news", "reviews", "features", "iphone news", "android news"); var navBarLinkArray:Array = new Array("http://feeds.feedburner.com/T3/news.rss",
Code:stage.addEventListener(KeyboardEvent.KEY_UP, reloader); function reloader(e:KeyboardEvent):void {[code].....
and this:
Code: var reloadT:Timer = new Timer(2000, 2); reloadT.addEventListener(TimerEvent.TIMER, on_timer); reloadT.start();[code].........
So I have a code that tracks Key_UP and one for a timer. However, I want to somehow use them together, like inside each other: ex. Run the timer function in Key_UP.I want to trigger the timer only if Key_UP is found. How would I do this?
Is it possible to call javascript functions inside flash (as3)? How about not in the same domain? Can you provide an example snippet for samedomain and not same domain?
I'm loading website by using htmlLoader.loadString(someHtml). There are included JS sources.Is there any chance to get access to functions which are inside this JS file?
I also set property placeLoadStringContentInApplicationSandbox to true.
I'm trying to detect the event.target of another function in the same calsses.
ActionScript Code: public function menus():void { menuArray[i].button.addEventListener(MouseEvent.ROLL_OVER,btnOver); } private function btnOver(event:MouseEvent):void { bgGlow(); } private function bgGlow():void { square.x=[B]event.target.parent.x[/B]; }
Here is a simplified of the coding that I'm trying to target.
var q4:Boolean = false; //Will have thirty-eight of these, q4-q41
function noRepeat() { if (q(_root._currentframe) == true) { gotoAndStop(randRange(4, 41)); } else if ((q(_root._currentframe)) == false) { q(_root._currentframe) = true; } }
Now, my problem is the bits in red (yes, I know they don't work, that was just the best way I could think to describe what I wanted).
If I create a string that says "q4" then I find it won't compare that to the boolean variable, but I'm positive there must be a better way than putting one of these on every frame.
So, performance wise, is it necessary to null references to classes, etc inside a function? Something like: Code: function myFunction():void{ var myVar:myClass = new myClass(); //do stuff with myVar... //don't need myVar anymore myVar = null; //is this necessary? }
How do I move / create a button that functions inside a movie clip?I have been creating a quasi-simple website following the tutorial provided by Lynda.com. Using I have created a functional site in which the buttons work so long as they are part of the main timeline. However if I take this functional button and drop it into a movie clip I've created, it ceases to function. Drag it back out of the movie clip and it starts working again. I am sure it's an action script coding problem on my end.[code]
I am loading an xml configuration file and based upon values obtained from it, I am connecting to an xml socket in the server.
But I can't register for socket.onConnect Function now. I could do it in my old cold in which I didn't use a configuration file. The configuration values are loaded properly. It seems the issue is in the way, socket.OnConnect function is registered.
After loading the movieclips and text boxes dynamically I now need to get the movieclips to perform a unique function when they are pressed, for testing purposes I am using the getURL funciton and linking to the boxNo. This is just so I can see what is going on!At the moment they are all linking to the boxNo that is pulled from the last run of the loop.
for (var i = 0; i < loc.length; i++) { var boxNo = loc[i].location_ID;;
I'm trying to create multiple Functions inside a Loop.[code]I essentially want to make 4 Functions called closeButOut1, closeButOut2, closeButOut3 and closeButOut4.This is the error message I get:
-1084: Synax error: expecting identifier before this.
-1084: Syntax error: expecting leftparen before rightbracket.