ActionScript 3.0 :: Flex Get Variables And Functions In Imported Swf
Jun 9, 2010
I'm loading in a flex application a .swf via <mx:Image> (that is a subclass of SWFLoader). Is it possible to retrieve a list of all the public variables and functions inside the loaded .swf?
I have imported some info from an xml file into my movie. The info from this file is then displayed in dynamic text boxes. Three of these text boxes show a price which displays fine. However i need the contents of these text boxes to be added together in another dynamic text box called total. I need this total to update as the price fields change. I just cant figure it out.
Here is my code which is placed at frame 1 of my movie:
The last line of code is along the lines of how i think it should work
and does not write "false" back to the global that was defined on the setup script, rather it creates it's own "local" global variable called _global.shorts which is no good to man nor beast!
I have tried using _root._global.shirt, _root.shirt, adding the variables to the loadMovle call, but nothing seems to let me trace the global with the correct value in the shirt popup.
Is there something I need to do to pass the variable to the shirt.swf when I load it?
I'm trying to make methods available like so: ActionScript Code: MyClass.myFunc(); Instead of ActionScript Code: var myVar:MyClass = new MyClass(); myVar.myFunc();
I know that to do so I need to declare the functions/variables/constants as static: ActionScript Code: package MyPackage { public class MyClass extends Object { public static function myFunc():void { } public function MyClass() { [Code] .....
When I try to access the static function through the full reference (i.e trace(MyPackage.MyClass.myFunc);), it works, while trace(MyClass.myFunc); returns undefined. This contradicts what I've read in tutorials and posts on the Internet. They all use the short syntax, not the full path.
If I have a function and I want to call a variable from another function (only 1variable), how do I do it? I know in the olden days you could set the variable to local or global, but that does not seem to work anymore. There is only 1 variable I need access to, but all the tutorials I have come across talk about making classes for multiple variables.
Code: function myFunction(val0,val1,val2){ trace(this["val"+0); trace(this["val"+1); trace(this["val"+2); } myFunction("hello","test","hi")
All i get is undefined. If i just put "trace(val0)" i will get "Hello" -- so i cannot work out how to get the value of the dynamic variable inside hte function?
I got this variable:[code]is there a possibility that the compiler gets confused because my variable has the same name like the functions's parameter (type = type)? i'm not certain about this topic. Normally I'd write my function's parameter like this (if such a case occurs):[code]just to make sure the names do not exactly match.
Code: function createTextBoxes() { for (var n=0; n<caption_obj.textXML.length; n++){[code].....
The XML portion is working fine. What I'd like to be able to do is access the created text fields outside of the function. For example:
captions1.alphaTo(0,1,"linear",1);
This works fine when it's inside of the function, but outside of it, it won't. Basically I need to time the captions to things that are happening in an animation. The animations are also tween driven, so it would be something like obj_mc.tween("_x", 200,2,"linear", 5,fadeOutCaption1); with fadeOutCaption1 being a function that fades out the first caption and brings in the second. If there is a better/more effecient way of doing this let me know.I also can't seem to apply any styles to the text field. Do I need to create an array or object with ["captions"+n] and then pull from that?
I have an animation that has roll overs controlled by AS (see code below). It works the way I have the code, but it's really messy code. And I hate that I'm have the functions rewritten for each event.How can I simplify this code?
//On the main timeline var gearsEnabled:Boolean = true; var gears2Enabled:Boolean = true;
I know PHP, JavaScript and AJAX. All of these other languages easily allow me to pass variables through a function, but I can't seem to work out how to do it in ActionScript 3. As you can see from the code below, I have created a variable called 'flag', this variable is set to 'notAdded'. However, once the function is called, I want to change the variable to 'added'. This for some reason does not work, the variable update only works within the function itself. There seems to be no global scope for functions.
Code: var flag:String = "notAdded"; bobRunning.addEventListener(MouseEvent.MOUSE_UP , bobRunningUp); if (flag=="notAdded"){function bobRunningUp(event:MouseEvent):void{ bobRunning.width = 30; bobRunning.height = 30; flag = "added"; }}trace(flag);
I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it's declared inside the constructor. However I can't use m_Bounds even though it's declared in the class.[code]...
I have a variable in the _root called 'ordered'. I have another variable called 'total' inside a function called 'loadXML'. 'total' receives a number value from a node in a XML file correctly. I now want to transfer this value to the variable 'ordered' which, as I said, is in the _root. However, 'total' is restricted to the function and I can't access it from the variable in the _root. Neither can I transfer the value from the variable in function to the _root.ordered, since such a line targets the _root of the function itself.I guess this isn't too hard to solve, probably just a path issue, but I have a few rather large gaps in my knowledge of actionscripting.On the stage, there are three objects; a movieclip with the instance name 'clip', a movieclip with the instance name 'orderbox' and finally a dynamic text field with the instance name 'pos_txt'.[code]
I am building a flash photo gallery that is fed by an XML file, now I am fine with all of the XML things in flash, my problem comes when creating the thumbnail images onRelease event. Here is my code:
Code: _global.counter = 0; for (_global.counter = 0; _global.counter<itemArray.length; _global.counter++) { //populate thumbnail array with URLS
[code]....
The problem is that when I release the mouse button I get a variable undefined error in the output window. I have researched and have found that my problem is that I can't pass a variable from the main function to the onRelease function.
how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e. **************************** var int1 = 1 var int2 = 2
[Code]....
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
I'm working on a project for school which is requiring me to make a game using Flash and ActionScript 3.0. One of the tasks I have to do is load an external XML file that will be displaying questions and answers. I've looked at google to find simple scripts for loading XML, one example being below:
Code: var myXML:XML; var myLoader:URLLoader = new URLLoader();
I was wondering if ActionScript had some way to call functions and classes from variables, like they do in PHP:
function funcname() { print "Potatoes come from tree"; } $function = "funcname"; print $function; // Prints out "funcname" $$function(); // Prints out "Potatoes come from tree"
In case you don't know the syntax for PHP, you should know that anything perpended with a $-symbol is a variable.
I'm starting to get a handle on some AS3 basics in terms of building nested classes or packages or whatever the proper syntax terminology is.
Now I have two instance functions:
1 - parseXML
2 - loadImage
I have these 2 functions working together using an eventHandler. Once the XML is parsed the aim is to load an image. Sounds pretty common right?
When the image loading commands are in the parseXML function they work fine. But then when I put the image loading commands in separate function titled loadImage and trigger it using an eventHandler onComplete, it loses my variable and instance definitions.
it's just some little white 'snowflakes' that fall from the upper end of the screen)
ActionScript Code: var timer:Timer = new Timer(30); timer.start(); timer.addEventListener(TimerEvent.TIMER, onTimer);
[Code]....
Now, this of course gives a run time error (access of undefined property snowSpeedX) due to the fact that snowSpeedX is declared in the function onTimer. The reason it is declared their is because i want it to change everytime and so each snowflake that falls, moves in the x axis with a different speed. If i declared the snowSpeedX variable outside of the onTimer function, i wouldnt get a different value for every snowflake, i would just get one.
So, how do i get the snow flakes to have a varying range of speeds?
I've created a basic function that sets a movieclip to a certain state depending on which mouse cursor is set (determined by a variable called txt_cursor). I can hard code this to work great for the one single movie clip but potentially have to do this for 624 other movie clips so obviously want to create a for loop to reproduce this.
I'm having problems in setting three variables using a for loop and then passing these variables to my function. I think it's something to do with the set function I'm using, because my colorFadeTo function claims it's being passed an undefined variable.
Code: for (var i=0; i<circles.length; i++) { var current = circles[i];