IDE :: Importing A Mp3 File - Nested Anonymous Function?
Apr 20, 2009
I am trying to play an MP3 File in Flash Lite 2.1 (I'm using Flash 8 to develop it). The filename of the MP3 file is imported from an XML file.Here is a copy and paste from the help file on how to do this:
// create a new Sound object
var my_sound:Sound = new Sound();
// If the sound loads, play it; if not, trace failure loading.
my_sound.onLoad = function(success:Boolean) {
[code]....
When I test this code on its own, it does work fine for me. However, I want the above to be executed inside a function that does a number of other things...
Here is a sample of what I'm trying to get working.
function myMusic() {
// create a new Sound object
var my_sound:Sound = new Sound();
// If the sound loads, play it; if not, trace failure loading.
[code]....
I think it's got to do with the fact that once I put it inside a function you are nesting functions (there is a function call from the onLoad event).
I tried changed the line:
my_sound.onLoad=function(success: Boolean) {
to
my_sound.onLoad=myFunctionName(parameters go here)
and then I created a funciton called myFunctionName but I wasn't sure how to send the sound object or what parameters the function should have or how to get the .start() method to work inside the new function.
I have a swf named garage. When you click the garage door it opens and a tool chest emerges. You can either click on the gargage door again to close it or click on the top of the tool chest to close it. The drawers on the tool chest represent buttons that will bring up a contact form to be sent to the perspective person. These buttons are a secondary navigation. The main movie that is importing garage.swf has navigation for the contact forms. I need to code the buttons on the tool chest to match the code on the main movie so if you click the buttons on the tool chest they will respond as if they were the buttons in the main movie that it has been imported by.
I have an event listener with an anonymous function literal, rather than a function reference. What I am trying to figure out is how to remove that event listener.Obviously, I need a reference to the anonymous function, so the two functions are ===. But, something is going wrong... it just doesn't work, ad this situation doesn't generate any feedback to tell me what might be wrong.There is some good info here, but not a clear explanation.
Code: private static var _myFunc:Function; public static function addCreditsToolTip(clip:DisplayObject):void
In as3, I am adding event listener and then attaching the anonymous function to it:[code]Now this whole piece of code is looped n times. Now, I have n myBoxes and whenever I roll my mouse over the box, it should alert the name. But, what I see is that the last value of count is used by each box. How can I pass parameter or value to the anonymous function? ( as roll over , I believe, expects only one variable)
little bit what Im trying to do: I have 2 SWF, one.swf and two.swf 1 LocalConnection to send 1 variable from one.swf to two.swf
one.swf code:
var param:Number = new Number(5); var sending_lc:LocalConnection = new LocalConnection(); sending_lc.send("_Connection1", "myMethod", param);
[code]...
I need to be able to use param value out of the function, because a I need to perform a switch with this value, since the function wich receives de param value is an anonymous function I dont know how to do to get the value from outside the function because a dont have a reference name to the function so, the normal way to return a value is not going to do the job.
up.addEventListener(MouseEvent.CLICK, function clickFunc(event:MouseEvent):void { revealSpinner(event,51.42,1,spinner);
[Code].....
The above code adds a listener to a couple of MC's. Originally the methods were anonymous but I have named them clickFunc() in order to try an reference them in my remove listener.
Here is my remove listener code. Both of these snippets are in separate functions. The add listener method is called before the remove method.
If I want to send an object to a function with one child called foo equals "bar", i need to do the following:[code]is there a way to declare the object in the function itself ? something like that:[code]
Getter functions allow obj.meth syntax instead of obj.meth(), I'd like to create an anonymous one of these to return from another function. function get ():Object { } is invalid syntax. I don't suppose Flex offers an easy way to get this functionality, if it's even possible?
I'm trying to differentiate anonymous functions like:
function() { trace("WOO"); }
from the other ones ('named'?) like
var _FUNC:Dynamic = function() { trace("WOO"); }
The reason I want to do that is because I can't compare between two anonymous functions, because they are two different ones.
var _TEST:Dynamic = function(a:Dynamic):String { var _TESTA:Dynamic = function() { trace("WOO"); }; var _TESTB:Dynamic = _FUNC; return (a == _TESTA) + ", " + (a == _TESTB); }
If I run _TEST(_FUNC);, I'll get back "false, true". Even though they are the same function, they are NOT the same object.Is there a way to compare those such that functions that they are the same if they perform the same task? Is there a way to serialize functions? So that maybe I can compare the serialized representations and see if they share the same 'code'.
In c++ if I have a function that takes a class I have defined elsewhere as a parameter like so:void moveto(CPoint2D point) { ... }I can invoke it and pass along data to it like this:moveto(CPoint2D(0,0));basically creating the object and invoking it's constructor to be passed to the functionIs there an equivalent to this in AS3?if I have a function like this:function initialize(min:Point, max:Point): void { ... }how do I do something along the lines of :initialize(Point(0,0), Point(10,10))This throws an error im assuming because it thinks I want to cast something to a point and the notation I found earlier to do something similar only seemed to work if using the basic Object class.
I'm new to AS3, and can't figure out why this loop isn't behaving the way it "should."
[Code]...
How can I give each anonymous function a reference to each object represented by f, rather than a simple reference to f each time? Specifically, why is it that each copy of the anonymous function gets bound to a single reference to f? How (I should say why) exactly does AS3 differ from JavaScript in this regard?
I am building my short flash as3 tweener driven movie.I have some mcs that have their own animation and they are placed on the stage.I am finding that flash is requiring me to continually put:
Code: import caurina.transitions.* into the beginning of every nested mc timeline.
I was wondering if someone could give me another clue.I am building my short flash as3 tweener driven movie.
I have some mcs that have their own animation and they are placed on the stage.
I am finding that flash is requiring me to continually put: Code: Select allimport caurina.transitions.*into the beginning of every nested mc timeline.
Am I doing everything right? Seems like this shouldnt be necessary since it is imported on the main timeline already..
I have a button labeled 'blueButton' and I'd like to use an anonymous function to handle the click, like so:
blueButton.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void { trace( "-----click detected-----" ); // now do other stuff });
Problem is, the click handler is called multiple times per click. The number of times called seems to be random (sometimes 2, sometimes 4, sometimes 3 etc). could I be missing something in my code, or maybe I set up the button wrong?
also I noticed that it seems to always get called once on the first click. After the first click is when it starts getting called additional times, maybe that has something to do with it?
I need to get a javascript var in my Flash application. I like to be able to just set a variable in the javascript (client constraints) rather than define a function.
Can this be done? I am trying to use the ExternalInterface.call()
I am having an issue where if I import a graphic to the library or directly to the stage, it causes my movie to stop on frame #1, even though the graphic is on frame #40. I have tried a .png, .jpg, and .psd and they all cause this behavior. I have put other graphics in and never had this issue.
basically i imported a SWF within my flash file from an external file and only the randomize button works on the file none of the rest from the imported flash can anyone let me know why, if you need me to let me know and i will upload files
Great book but I'm finding stuff that's not working as it's supposed to The first item I came across was adding a stop(); on a separate layer at the end to stop my swf from looping. I followed the directions to a T but no matter what, the .swf would loop. I came across another forum where it mentioned to change the publish settings to Player 8 which automatically changed the ActionScript to 2.0 instead of 3.0. Well the movie didn't loop anymore but why shouldn't it work with Player 10 ActionScript 3.0? I have the most up to date player that I can get.
The next item I came across was on the Import Video function. The tutorial was to use the video encoder to make a usable movie for my file. When I tried to import it I got nothing, no errors, nothing appeared on my layer as it was supposed to. Same thing here - I changed my publish settings to Player 8 which, again, changed it automatically to Actionscript 2.0 and then the movie imported fine and played and did everything it was supposed to do.
I have kept 12 buttons inside a Movie Clip. When I refer this with dot and when clicked it works fine. But the same is not working with function. This works
ActionScript Code: scroll_mc.Feb.onRelease = function() { var month:String; month=this._name;
Is it possible to import a swf file into a Flash file with a transparent background so you can still see the main movie underneath? Also, I would only want the swf file to play on a certian number of frames. By the way I have the original flash file of the swf I want to import.
I have been searching on this and from what I have read in some posts I found through google it seems that it is possible to import an .mp4 file to flash.... I am unable to do this so far and wondering if it is in fact possible to do this.. if so, does anyone know of any decent .avi to .mp4 conversion software that will allow the mp4 to be imported to flash as the ones I have tried so far are not allowing the mp4 to be imported.
I'm new at AS3. I'm pretty good when it comes to PHP, MySQL or HTML but I'm totally lost in AS.I have a project in Flash Builder 4 that I'm trying to add something to that was built in Flash Professional. It's supposed to loas a couple of external AS files, then execute functions from them at a certain point in the application. I know where I want the functions to execute in the application, and I have linked the AS files to "test.as" which is the main AS file for "testapp.mxml". The problem is calling the "Detector" function from inside "FaceDetector.as" which is one of the external AS files. What is the best way to do the following.[code]I want to start the script and let it do what it's supposed to do inside the application at that given time.
I have a movieclip "squareA" -- inside of squareA, on frame 2 is a movieclip called "squareB". I tried the following code: Actionscript Code: squareA.x = 10squareA.y = 10squareA.gotoAndStop(2)squareA.squareB.x = 10squareA.squareB.y = 10
But I get the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at problem_fla::MainTimeline/problem_fla::frame1() If I put SquareB in frame 1 of SquareA -- it works.
If I have function_2 nested inside function_1, how would you call function_2 from another movieclip on the same timeline?MovieClip(parent).function_1().function_2()-I know that's incorrect, but just to illustrate.
I need a way to call a function from a function. It's not that hard, I know, but the name of the nested function is a variable passed into the first function. Like in setTimer() and other functions in flash, where you have the name of a variable to call. I'm going to have a lot, so doing some cheap if(funcname == blabla){blabla();} won't work.
As entitled in this post, suppose we have wrote in timeline
[code]...
The problem emerges because I want to use local variables (i.e. a and b) to perform tasks of myF2 on several clips at the same time but started, say, a half of second one after the another. I don't want to use timeline variables because all clips must start with the same initial variable values.If it's impossible to use setInterval like this, how is it possible to fix the problem I described here? .This code is for Flash Professional 8.0