How do you pass in complex objects into a brightcove plugin? - actionscript-3

I am creating a Brightcove plugin. The documentation implies that if you need pass in data to your plugin that you need to do that by attaching flashvars to the swf url. (example: myPlugin.swf?myVar=foo&yourVar=bar )
Is there another way to pass in vars? I want to be able to pass in an array of objects, each which contain objects as their own into my plugin.
If there isn't another way, how do I do that with a flash var string?
Ideally, I'd like to be able to use the BEML paradigm to pass in various XML style nodes and then parse those into classes.

BEML is only to style your player and to attach modules/plugins.
If you download their GoogleAnalytics example.
You can build your plugin off that, and also this is how I was able to use Flashvars with that particular plugin:
myVar = this._bcStage.root.loaderInfo.parameters.flashVar;
I needed the _bcStage in order to get access to the HTML.

Related

How connect json file with after effects for rendering dynamic video

I wan't to learn how connect some json file with after effects for rendering dynamic videos.
Eg i have a form in some webpage:
this form included one input which people are using there their name.
And then i create some json file like that array of objects with this form.
data = [
{
name: 'John'
},
{
name: 'Mike'
}
]
and i wan't to create with these json objects for each name some video about few second there will be shown just name from json and render some mp4 video.
How to do that?
which steps following?
if it will be web form i think i'll need to connect json file dynamically too right?
so after effects will read this json file from some url ?
There are many ways to go about doing this, but a single answer on Stack Overflow probably won't give you everything you need.
Network communication can be done using the CEP framework provided by Adobe which can then execute ExtendScript code which actually does the manipulation of the layers inside the AEP project file. You can use node modules to perform the network communication, and then write ExtendScript code to pass in the JSON data to that.
While not free, you might want to explore Dataclay's Templater extension to help you accomplish what you want. It not only does what you are asking out of the box, but it has some rules-based AI to reconfigure layers both temporally and spatially. You can point Templater to a URL that response with an array of JSON objects and have it process that data. In addition to this, it has event hooks which allow you to execute any script within the Shell or with the ExtendScript engine during its versioning process.
Hope this helps!

Embed a JSON file in an SWF

Can I use include in actionscript in some form?
var somevar = include "file.json";
Where "file.json" contains JSON data
It's not this simple, but possible. First, you have to embed a JSON file as is:
[Embed(source = 'file.json', mimeType='application/octet-stream')]
private static const YourJSON:Class;
Then, to get whatever is embedded (a String, a Bitmap, an SWF), you need to instantiate a variable with this type.
var somevar:String=new YourJSON();
Then you need to parse the JSON, the correct syntax for this varies by JSON and parsing library (this part is mainly determined by your Flash player target). RafH's answer has a syntax for an array and (IIRC) FP10 compatible library.
Also may want use ASC 2.0.
(from here)
New syntax allows you to use:
var h:Object = include 'conf.json'; // where conf.json contains correct JSON
No, include doesnt return a value and includes are done at compile time, so if the content of the include file change, you need to recompile the swf.
Not sure about you want to do, but it seems like loading / parsing an external JSON data file would be a better approach to look for.
Here is a good example : http://snipplr.com/view/56283/

converting gwt shared object to json

Could someone explain to me why in GWT you cannot convert a client/shared pojo (that implements Serializable) into a JSON object without jumping through a load of hoops like using the AutoBeanFactory (e.g GWT (Client) = How to convert Object to JSON and send to Server? ) or creating javascript overlay objects (and so extends JavaScriptObject)
GWT compiles your client objects into a javascript object, so why can't it then simply convert your javascript to JSON if you ask it to?
The GWT JSON library supplied only allows you to JSONify java objects that extend JavaScriptObject
I am obviously misunderstanding something about GWT since a GWT compiles a simple java POJO into a javascript object and in javascript you can JSON.stringify it into JSON so why not in GWT?
GWT compiles your app, it doesn't just convert it. It does take advantage of the prototype object in JavaScript to build classes as it needs, usually following your class hierarchy (and any GWT classes you use), but it makes many other changes:
Optimizations:
Tightens up types - if you refer to something as List, but it can only be an ArrayList, it rewrites the type declarations. This by itself doesnt give much, but it lets other steps do better work, such as
Making methods static - if nothing ever overrides ArrayList.add, for example, this will turn any calls it can prove are to ArrayList.add into a static call, preventing the need for dynamic dispatch, and allowing the 'this' string in the final JS to be replaces with a shorter arg name. This will prevent a JS object from having a method you expect it to have.
Inline Methods - if a method is simple enough, and is called in few enough places, the compiler might remove the method entirely, since it knows all places where it is called. This will directly affect your use case.
Removes/Inlines unreferenced fields - if you read to a field but only write it once, it will assume that the original value is a constant. If you don't read it, there is no reason to assign it. Values that the compiler can't tell will ever be used don't need to be using up space in the js and time in the browser. This also will directly affect treating gwt'd Java as JS.
After these, among others, the compiler will rename fields, arguments, and types to be as small as possible - rarely will a field or argument be longer than 1 character when this is complete, since those are most frequently used and have the smallest scope, so can be reused the most often by the compiler. This too will affect trying to treat objects as JSON.
The libraries that allow you to export GWT objects as JSON do so by making some other assumption.
JavaScriptObject (JSO) isn't a real Java object, but actually represents a JavaScript instance, so you can cast back and forth at will - the JSNI you write will emerge relatively unoptimized, as the compiler can't tell if you are trying to talk to an external library.
AutoBeans are generated to assume that they should have the ability to write out JSON, so specific methods to encode objects are written in. They will be subject to the same rules as the other Java that is compiled - code that isn't used may be removed, code that is only called one way might be tightened up or inlined.
Libraries that can export JS compile in Java details into the final executable, making it bigger, but giving you the ability to treat these Java objects like JS in some limited way.
One last point, since you are talking both about JSON and Javascript - Some normal JS isn't suitable for writing out as JSON. Date objects don't have a consistent way to serialize that is recognized by JSON. Non-tree object graphs can't be serialized:
var obj = {};
obj.prop = {};
obj.prop.obj = obj;
Autobeans come with a built in checker for these circular references, and I would hope the JSO serialization does as well.

How to I pass Vector.<> from Flash with ExternalInterface

I have a custom container (C#) for the Flash ActiveX control and am passing data back and forth. Previously I would use ExternalInterface.call and pass an Array as a parameter. I would prefer to use the Vector class now that it is available, but it appears that when I do that the call is never made.
It is however made if it is embedded in IE. It appears that when in IE, Flash will send out JavaScript to execute rather than serializing to XML. My guess is that the Vector XML serialization isn't baked in, so Flash just ignores the call.
Anyone have any ideas? Other than just going back to using Array, I've already done that for now.
The docs note that:
Other built-in or custom classes -
ActionScript encodes other objects as
null or as an empty object. In either
case any property values are lost.
It's not completely clear what that means, since custom classes are also Objects - I guess only vanilla objects count? But at any rate it looks like Vector falls into that "other built-in classes" category, so you'll need to either use Array, or re-cast to Array before you pass the data.
you can use arrays with [ArrayElementType("type")] instead. or write a serialization function for Vector

how to enumerate object tag parameters from loader page via AS3?

I have a few object params in HTML page I like to enumerate, what is the easiest method?
I would like to use for loop to go through each param and insert them into my own Array.
If you are referring to the parameters of the <object> element (such as allowfullscreen, wmode, quality, etc.), I don't think there is a generic way of accessing these values from within AS3. To access these values, I guess you probably need to have some sort of mechanism outside flash to pass these parameters to the flash object. E.g., you could use SWFObject to generate the embedding code, and pass the array meant to be used as params in the flashvars argument as well.
If, on the other hand, you mean the value of the flashvars parameter, i.e., those values which are meant to be passed to the flash object, you can access these values via the Applicaiton.application.paramaters object (keys are parameter names, values are corresponding values). In case of a plain AS3 project, the same array can be accessed via root.loaderInfo.parameters.
HTH