-
Website
http://www.abdulqabiz.com/blog/ -
Original page
http://www.abdulqabiz.com/blog/archives/2006/06/16/a-mxml-component-that-embeds-javascript-in-html/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
melanie12345
1 comment · 1 points
-
kanti
1 comment · 1 points
-
anuradhashinde2001
2 comments · 2 points
-
joeboxer
1 comment · 1 points
-
petkusj
2 comments · 1 points
-
-
Popular Threads
- JavaScript injection through ActionScript
- JavaScript injection through MXML
- Inject JavaScript through MXML or JavaScript
Listing, so that search-engines can index this comment and show this entry..
-abdul
Question though, In my component I had to strip out "\n", "\r", etc.... how did you get around this? navigateToURL decode this stuff for you? ExternalInterface did not.
One other thing to think about, should the script keep track of what it has sent to HTML already? What if a component contains JavaScript and you need two instances of the component? Would that send the script twice? If so, are two sayHello() functions allowed in javascript? Didnt test if thats the case but I have a static array to keep track of all source properties so it only sends it once.
About the subject, you'd have a much better chance if you linked to the blog entry with the various subject lines as the anchor text.
Anyways, hope this idea has some use-cases. I have some in my mind. I would post some examples.
Scotty, I tried using ExternalInterface then I realized I don't need it because it is one way call. And I also faced issues you mentioned.
I have not checked but you can create multiple instances of JavaScript component and inject scripts...It should work, I am just using "eval()" to make it work.
If you try to inject a function, which is already present. New injection would override the things...
-abdul
Use cases...
if your component relies on javascript and dont want to have to make sure the calling page contains a special wrapper.
Another being a way to hide your javascript logic, kinda of an encryption method. Im not sure if there are Javascript debuggers that pay attention to eval()'ed calls.
Best Wishes,
Tim Hoff
-abdul
yours,
T#
May be it's newline character or comments or could be anything.. For simple statements/expressions ExternalInterface works.. but complex ones, it doesn't..
Please try to port one my examples, in separate post , using your technique and see if it works..
Thanks
-abdul
<pre>
<JavaScript>
<![CDATA[
location.href = "http://www.yahoo.com";
]]>
</JavaScript>
</pre>
Mabybe you could evaluate that the double slash is not between quotes.
Cheers
I am not very good in RegExp, I have fixed it anyway. I am going to sit down and write down all the use-cases and write proper regexp patterns.
I guess, I would end up writing some kind of laxer/grammar :)
-abdul
i am using eclipse with flex plugin...but i get an error saying "could not resolve to component implentation....where should i put JavaScript.as that u have mentioned and how should i run it in eclipse..
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:utils="com.abdulqabiz.utils.*" ....
If you are using JavaScript in ActionScript, import it:-
import com.abdulqabiz.utils.JavaScript;
I noticed this very peculiar behaviour:
try putting this in a javascript function and execute it as you said:
alert ("aaaaaaaabbaaaaasdddddddddddd2aaaaaaaaaaaaaaa1sasaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1");
I got differing results in different browsers. It basically does not work in IE6. All other javascript functions don't work also if on the same flex app or html page.
However this works in IE7 and Firefox. It only works in IE6 if the piece of code above is put into a normal html page and not executed through Flex.
wondering what's going on and if there is a workaround to the limit of characters in a string
I keep getting:
SecurityError: Error #2051: Security sandbox violation:
errors with this example.
thanks for this code. i'm trying to integrate multiple javascript files into a flex application. i copied the code from your javascript.as file and tried to use the javascript tag in a separate mxml component file but it didn't work. it says that it could not resolve to a component implementation.
do you know what i could be doing wrong?
hopefully you're still getting messages about comments from this post!
thanks!
so i fixed the problem that said it could not resolve to a component implementation (i think), by using but now it has a problem with "packages cannot be nested" in javascript.as
do you know what i could be doing wrong?
thanks!
nevermind. i had just named the file differently from the class. it's all fixed now. thanks for the code!
it's very nice one,Right now i am doing session based flex application,so while closing the browser i need to pass the flex event,can u please guide me,
thanks in advance
1) Capture browser's unload event and do the cleanup (saving data, closing session, etc).
2) Warn user when he tries to close the browser, request him to save, exit or logoff using provided control in user-interface?
3) Maintain a persistent connection using sockets or xmlsocket, now that might be some work and requires server-side infrastructure.
#1 might not work in all browsers and #3 might be little too much for simple things. I see, #2 can be used to and it's safe and sound.
BTW! What you plan to do? I mean, a lot of people are generally confused with things "sessions" and "flex".
-abdul
I believe, you can