Newbie to this

14 views
Skip to first unread message

neerajs...@yahoo.com

unread,
Oct 28, 2011, 9:39:05 AM10/28/11
to JSInterface
I have the following Javascript file.

goog.provide("com.pf.sy.cdm.PreDefCDMTypes");

var ns = com.pf.sy.cdm;

/**
* Sy PreDefCDMTypes function
* Creates predefined CDMTypes.
* This class creates predefined CDMTypes for Sy3 core
* when an instance of the class is created.
* @export
* @param
* @constructor
*/
ns.PreDefCDMTypes = function () {
this.CDMTypes = {
"CDM": {
"String": {
"typeOf": "string",
"minoccurs": "1",
"maxoccurs": "1"
}
}
}
};

ns.PreDefCDMTypes.prototype.mergeDefinitions =
function(typeDefinitions) {
returnString = "";
for(var i=0; i<arguments.length; i++) {
for (var j in arguments[i].CDM) {
if (this.CDMTypes.CDM.hasOwnProperty(j))
{
returnString = j + " already exists and cannot be added. Rename
your CDM type definition and try again.";
break;
} else
{
this.CDMTypes.CDM[""+j+ ""] = arguments[i].CDM[j];
returnString = "Success";
}
}
}
return returnString;
};


How do I access CDMTypes from Flex using JSInterface or run my
mergeDefinitions function?

Thanks

Neeraj

Олег Галабурда

unread,
Oct 28, 2011, 10:09:16 AM10/28/11
to jsint...@googlegroups.com
Hi!

From your code I can say that you need to instantiate ns.PreDefCDMTypes first:
var obj:JSDynamic = new JSDynamic("ns.PreDefCDMTypes");

then call method
var result:String = obj.mergeDefinitions(typeDefinitions);

In your case typeDefinitions is a complex type -- multidimensional
collection, so in JavaScript it may appear as FLObject instance. To
prevent this, wrap your data into JSSimple instance while sending to
JavaScript:
var result:String = obj.mergeDefinitions(new JSSimple(typeDefinitions));
This will guarantee that your data will be transfered as is, like
using ExternalInterface, just copied.

If you want to preserve connection to Flash data(this means any
changes made in JavaScript will take place with original data in flash
player), check this docs
http://code.google.com/p/jsinterface/wiki/help_english#javascript

2011/10/28 neerajs...@yahoo.com <neerajs...@yahoo.com>:

--
Oleg Galaburda
http://blog.actualwave.com/
http://jsinterface.googlecode.com/
http://guibuilder.org/

neerajs...@yahoo.com

unread,
Oct 28, 2011, 1:06:30 PM10/28/11
to JSInterface
I tried creating the object as you suggested and it does not work.

Error: JavaScript object [com.pf.sy.cdm.PreDefCDMTypes] instance can't
be created.
at aw.external.jsinterface::JSDynamic/
aw.external::js_interface::createInfo()[Z:\home\localhost\www
\JSInterface\svn\source\lite\aw\external\jsinterface\JSDynamic.as:59]
at aw.external.jsinterface::JSDynamic()[Z:\home\localhost\www
\JSInterface\svn\source\lite\aw\external\jsinterface\JSDynamic.as:38]
at ExternalJavascriptCall/creationCompleteHandler()[C:\Users\nsingh
\Adobe Flash Builder 4.5\ExternalJavascriptCall\src
\ExternalJavascriptCall.mxml:35]
at ExternalJavascriptCall/
___ExternalJavascriptCall_Application1_creationComplete()[C:\Users
\nsingh\Adobe Flash Builder 4.5\ExternalJavascriptCall\src
\ExternalJavascriptCall.mxml:6]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects
\framework\src\mx\core\UIComponent.as:12528]
at mx.core::UIComponent/set initialized()[E:\dev\4.x\frameworks
\projects\framework\src\mx\core\UIComponent.as:1627]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x
\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev
\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:
1072]

I tried using ns.PreDefCDMTypes as well.

Any more suggestions?

Neeraj


On Oct 28, 10:09 am, Олег Галабурда <burd...@gmail.com> wrote:
> Hi!
>
> From your code I can say that you need to instantiate ns.PreDefCDMTypes first:
>   var obj:JSDynamic = new JSDynamic("ns.PreDefCDMTypes");
>
> then call method
> var result:String = obj.mergeDefinitions(typeDefinitions);
>
> In your case typeDefinitions is a complex type -- multidimensional
> collection, so in JavaScript it may appear as FLObject instance. To
> prevent this, wrap your data into JSSimple instance while sending to
> JavaScript:
> var result:String = obj.mergeDefinitions(new JSSimple(typeDefinitions));
> This will guarantee that your data will be transfered as is, like
> using ExternalInterface, just copied.
>
> If you want to preserve connection to Flash data(this means any
> changes made in JavaScript will take place with original data in flash
> player), check this docshttp://code.google.com/p/jsinterface/wiki/help_english#javascript
>
> 2011/10/28 neerajsingh0...@yahoo.com <neerajsingh0...@yahoo.com>:

Олег Галабурда

unread,
Oct 29, 2011, 4:18:40 PM10/29/11
to jsint...@googlegroups.com
Hi!
Just tried on empty project.
JavaScript code:
var ns = {};
ns.TestObject = function(){}
ns.TestObject.prototype.stringifyMyList = function(list){
return list ? list.join(", ") : "";
}

ActionScript code:
package{
import aw.external.JSInterface;
import aw.external.jsinterface.JSDynamic;

import flash.display.Sprite;

public class JSITest extends Sprite{
public function JSITest():void{
super();
initialize();
}
private function initialize():void{
JSInterface.initialize();
var obj:JSDynamic = new JSDynamic("ns.TestObject");
var result:String = obj.stringifyMyList(["1", "2", "3", "4", "5"]);
trace(result);
}
}
}

Output:
1, 2, 3, 4, 5

Everything working as expected, problem is specific for your project.
Move this code to your project and try to run it.

Check if you initialized JSInterface before using.
JavaScript should be accessible(loaded) when you are trying to use it.
Run application under HTTP(use local HTTP server, for example).
Read docs, try examples.

2011/10/28 neerajs...@yahoo.com <neerajs...@yahoo.com>:

--

Reply all
Reply to author
Forward
0 new messages