ActionScript 3.0 :: Dynamically Populate A Function At Runtime?
Feb 25, 2011I am attempting to dynamically populate a function at runtime and then have the ability to call this function.
View 9 RepliesI am attempting to dynamically populate a function at runtime and then have the ability to call this function.
View 9 RepliesI'm trying to build an API in JS that will perform some operations and then execute the callback that's registered in AS when it's done. Because it's an API, I am just providing a JS method signature for another developer to call in Flash. Thus, the callback name that's registered in the AS part of the code should be a parameter that's passed in to the JS API in order for JS to communicate back to Flash.
For example:
[AS3 code]
ExternalInterface.addCallback("flashCallbackName", processRequest);
ExternalInterface.call("namespace.jsFnToCall", flashCallbackName);
function processRequest(data:String):void {
//do stuff
[Code] .....
Because the definition of the function is in AS, I can't use the window [function name] approach. The only way I can think of is to build the callback in a string and then use the eval() to execute it.
I am trying to figure out how to dynamically populate textfields in Flash. The text in the fields will either say ON or OFF based on the value of bstatus.var bstatus will either have a value of 0 or 1 I have the following textfields listed below.I'm not sure if the syntax is correct, but I was thinking that the text fields would be in an array, and I would create a for loop--that will go through the array in order to have the fields populated.
var textFields:Array = new Array();
textFields[0] = compTxt.text;
textFields[1] = bathLightTxt.text;
[code].....
I'm trying to populate a scroll pane dynamically with a moveclip but it isn't working. I can add an image with loadMovie, but attachMove isn't doing anything. The same thing works to a moveclip manually added to the workspace, but not on my dynamic scroll page.
ActionScript Code:
for (var i = 0; i<clipArrowArray.length; ++i) {
var clip:MovieClip = scrollpane.content.pane_mc.createEmptyMovieClip("clip"+i+"_mc", i);
[code]....
I'm very sleepy right now, so this is just an example of what I want (obviously this code is wrong):
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
[code].....
URL...In this demo I have a Datagrid populated from a php script.I also have a ComboBox embeded in the datagrid. In this example I am reading the ComboBox data from an array within a ComboBox CellRenderer.The question I am posing is how to dynamically populate the embedded ComboBox's from a php script with data retrieved from a mySQL table.
View 0 RepliesI would like to create a function that adds a child to whatever mc i choose like this where targetMc is the mc that i want the child (libraryMc) to be added to
PHP Code:
functionName(targetMc,libraryMc);
so right now my function looks like this
PHP Code:
function functionName(targetMc:MovieClip,libraryMc:MovieClip):void
{
var libContent:libraryMc = new libraryMc();
targetMc.addChild(libContent);
}
i know this is wrong as new libraryMc() is also being replaced with the libraryMc:MovieClip and that is probably why it's not working.
I am using a gallery written in AS3.0 called SlicedCubeGallery. It used Flex to publish the gallery.I can edit the functions for the SlicedCubeGallery, and the one I am targeting is the one that swaps the images (which I have running on a timer).I am loading the whole gallery SWF onto my stage using this code:
var request:URLRequest = new URLRequest("slicedCubeGallery.swf");
cubeGallery_mc.load(request);
addChild(cubeGallery_mc);
[code]......
I'm trying to setup a DataGrid that contains a column of combo boxes. The values of the combo boxes are defined by data specific to that row. I cannot get this to work though, I'm asking for a solution to this, either fixing what I have below or a recommendation on a different way.One of the columns of my DataGrid has an object derived from a ComboBox for an ItemEditor. The itemEditor is set like this:
<mx:DataGridColumn editorDataField="selectedItem" dataField="type" editable="true" >
<mx:itemEditor>
<mx:Component>
[code].....
I have a custom component based on mx:ComboBox. Within it I connect to an HTTPService (the url is passed as a paramter) and bind the combobox. Parameters to be sent to the HTTPService are passed to the component. This is working fine. But I want to modify it to make it re-usable with other HTTP service URLs, which return the XML in a different format.
My challenge is how can I bind a custom component to a node dynamically at runtime?[code]...
I have a AS3 project in Flash CS4 in which I am dynamically loading in a font whose location is passed in via XML. It works when I write in the font name (here EASTERAR.TTF). However, if I replace it with a variable, I get an invalid metadata error.
Works fine
[Embed(source='C:/fonts11/EASTERAR.TTF', fontFamily="xyz")]
var xyz:Class;
var arialEmbeddedFont:Font = new xyz();
var textFormat:TextFormat = new TextFormat();
[Code]....
I am building a form builder in Flex 4.5. For that I need help regarding uploading image at runtime such that any user can just simply place cursor on particular location on image and is able to upload any image from the local file system.
View 2 RepliesI have a presentation with various embedded and external videos linked to it. I need them to be positioned in the center of the screen no matter what resolution the user is running, therefore I need to position them dynamically and not with specific co-ordinates. I have found a link and some code that does this, but its a big chunk of code and I would like to put this code in my main .as file, as a function, and then in my main timeline when I have a video - just use one line of code to call the function and apply it to a movieclip with the video inside.[code]...
View 3 RepliesI have a presentation with various embedded and external videos linked to it. I need them to be positioned in the center of the screen no matter what resolution the user is running, therefore I need to position them dynamically and not with specific co-ordinates. I have found a link and some code that does this, but its a big chunk of code and I would like to put this code in my main .as file, as a function, and then in my main timeline when I have a video - just use one line of code to call the function and apply it to a movieclip with the video inside.
[Code]....
I need to change the stage size dynamically. When I try to do this?
size_mc.onRelease = function(){
trace(Stage.height);
Stage.height += 100;
trace(Stage.height);}
It comes always the current stage size.
Is there a way to obtain a reference name of each item on the stage. A reference name that can be then used to manipulate the object? (and how would one do that if successful in obtaining the name?)
As an example that is not working for me, if I drag to stage two movie clips and dynamically include 5 additional movie clips at runtime, this [code]...
I have a flash file in folder "/" which loads another flash file in folder "/xyz/". The second flash file will load several resource files on its own. Now flash is looking for the resource files at the base folder "/" and instead of the other loaded flash's folder "/xyz/". The second loaded flash file is provided by a third party and can't be modified. Is there any way to dynamically change the base folder of the "application" at run-time? I've heard about the html swf tag "BASE" so I've tried loading the second flash file with a ".....?BASE=/xyz/" but it doesn't work.
View 0 RepliesUsing org.as3commons.reflect I can look-up the class name, and instantiate a class at runtime.I also have (non-working) code which invokes a method. However, I really want to set a property value. I'm not sure if properties are realized as methods internally in Flex.I have a Metadata class which stores 3 pieces of information: name, value, and type (all are strings).I want to be able to loop through an Array of Metadata objects and set the corresponding properties on the instantiated class.[code]I realize that I have to declare a dummy variable of the type I was to instantiate, or use the -inculde compiler directive. An unfortunate drawback of Flex.Also, right now there's code to account for typecasting the value to it's specified type.
View 1 RepliesI need to dynamically bind properties of components created at runtime. In this particular case please assume I need to use bindProperty. I don't quite understand why the following simplistic test is failing (see code). When I click the button, the label text does not change.
I realize that there are simpler ways to go about this particular example using traditional non-dynamic binding, but I need to understand it in terms of using bindProperty.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="Tools.*" minWidth="684" minHeight="484" xmlns:ns2="*" creationComplete="Init();">
[code]....
flash builder 4 comes with a couple of cool spark themes, and there are tons of others out there on the web, I want to be able to change the theme at runtime, without recompiling.
View 1 RepliesI've got a rather simple question about loading in an xml file at runtime in a SWF. I've found a couple different methods to load in the xml.
myXml.load("file.xml");
HTTPService object
URLStream object
What is better way to load an xml file that always has the same name and is located in the same folder as the SWF on the web server?
My problem specifically I am designing a user interface with controls on it. 5 buttons rotate left, rotate right, zoom in, zoom out, and auto rotate. The interface in itself works fine, I can trace out button clicks, toggle the auto rotate button etc...
My program reads an xml file. Loads some images, fills an array with links for each image, and when the image is clicked a loader loads a swf from a URL and displays it on screen. No problem.
Now I originally had the zoom controls user interface in the runtime_loaded.fla library, and the mouse listeners in the same linked document class. The interface works with the movieClip in runtime_loaded.swf when it is in the same code.
[Code]...
I want to use the same movieclips (some are button movieclips) but be able to have a function lay them out at runtime in two (or more) layouts. Just the _x and _y position like in this example:I'd like to layout the mcs with just actionscript. So it can be hardwired into the movie's script with parameters A yielding layout A, et cetera.
something like this:
Code:
boxOne_mc._x = 100;
boxOne_mc._y = 100;
boxTwo_mc._x = 200;
[code]....
but all wrapped up in one function.
How do I execute callback functions dynamically by passing a function in as an argument to another function?
Look at this example:
Code:
package {
public class myClass extends MovieClip {
public function myClass(callback) {
[code]....
Using Flex 3.2, I have a object which extends a TitleWindow. In this TitleWindow I have an AdvancedDataGrid.
On creation of this object, I pass it 2 lists, one full of data to display, and the other I pass an array of column definitions. This allows me to, at runtime, create the correct columns and define the correct display attributes for each column (e.g. booleans will show up as checkboxes, and dates are formatted in a specific format (coming in from an XML feed in a variety of STRING formats where nulls are a possibility)
The problem is that the default sort, being based on string, doesn't work 100% of the time and even when the format is one that would be sorted nicely, it fails when nulls are involved.
The above problem would be easily solved using a sortCompareFunction, but the fact is when you set the sortCompareFunction of the column, it seems to require you to hardcode in the column name into the function.
for reference here's the function I'm using to create the columns:
private function setupGrid():void
{
var localcols:Array = new Array();
[Code].....
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'.
I load many classes in at runtime from external SWF's, accessing those classes is pretty simple, like so -
var currentDomain:ApplicationDomain = ApplicationDomain.currentDomain;
var modelClass:Class = currentDomain.getDefinition(className) as Class;
var model:Model3D = new modelClass();
However I've never tried to access static functions from a runtime class, and now I need to. How is it done? It seems like something that should be simple, but I haven't worked it out yet.
I want to pass an optional data parameter to some callbacks, but only to callbacks that support a single parameter; right now, I have a moderately-sized code base of callbacks that cannot accept a parameter at all. How can I check what parameters a Function object supports?
View 3 Repliesi am trying to modify during runtime an image in my application, this image is located inside assets folder, so thats why i dissable -use-network=false flag, then i call something like this:img.source="../assets/pict.png";but it's not working.
View 1 RepliesI've seen the Loom project, but are there any alternatives that are more mature (and actively developed)? I am looking for something that would allow load-time weaving of pointcuts into existing binary code at runtime with the AVM2 runtime.
Has any work been done in this area?