views:

198

answers:

3

Hi All,

I am trying to make a call to javascript function from actionscript.

As of now, I am using 'ExternalInterface' and could achieve partial success.

I could make a call to function(without any scope resolution) like "scanDNA()", which is visible to all. But am not able to make a call to function(scope specified) like "Eukarya.Animalia.Chordata.Vertebrata.Gnathostomata.Tetrapoda.Mammalia.scanDNA()".

Please let me know, how can I achieve this.

Thanks and Regards,

SachinJadhav.

A: 

How about creating a method in JS to call the function?

function scanDNAinSomeScope(){
    Eukarya.Animalia.Chordata.Vertebrata.Gnathostomata.Tetrapoda.Mammalia.scanDNA();
}

And call that scanDNAinSomeScope using ExternalInterface.

UPDATE:

Yes, in that case you need to create a function for every scope. But, you actually only create for functions that you need to call. I believe there wouldn't be many cases you need to call functions from different scope from Flash.

And there is a workaround, using a JS function like:

function evil(str){
    eval(str);
}

It may be a security hole. But I'm not security expert, so I can't tell what problem it actually has... I know "eval is evil" only :P

Andy Li
I do not think this is useful...I want a way out of problem... This is kind of hack...
SachinJadhav
Why you think it is a kind of hack? What do you need more than that?
Andy Li
you would have to create such a function for every scope, not nice indeed
skrat
Updated for @skrat :)
Andy Li
A: 

I have never noticed any problems with this. How is your javascript scope structure set up?

Maybe leaving out the "()" in the ExternalInterface call could do the trick..

If I do

var animals = {}
animals.mammals = {}
animals.mammals.test = function() {
  return "whee";
}

and in flash (CS4)

var x:String = ExternalInterface.call('animals.mammals.test');
trace(x);

I get the correct result.

Les
A: 

Using the javascript pseudo protocol works well.

Dobby