Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript in flex application or alternative.

New Here ,
Apr 22, 2008 Apr 22, 2008
Subject: Looking for java (or pseudo-java script) solution

I am hoping someone can help me develop a work around solution to read HTML within my Flex/Flash application.

I have created a window within Flex that contains HTML text. I want my users to be able to click anywhere on the text and in turn, I want the Flex application to access the embedded hypertext.

Maybe I should say that I need the script to work on the client side and that I do not want to open a new window. Instead I want to be able to embed values in the HTML and then when the student clicks on the hypertext, this value is made available to Flex.

Is there a way to do this? I understand that much of the javascript is blocked, but is there a workaround solution that can accplish this? If it helps, I can work either in Flex 2 or Flex 3.

Thanks a lot.
TOPICS
ActionScript
404
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2008 Apr 22, 2008
you can use the externalinterface class to commuicate between flex and javascript.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2008 Apr 22, 2008
While the externalinterface class provides the Flex application funtionality with EXTERNAL javascript calls, is it possible to call Javascript from WITHIN the Flex application. For example, within the HTMLText of a TextArea. If not, is there a workaround?

Thank You
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2008 Apr 22, 2008
CoderAmungus,

> Subject: Looking for java (or pseudo-java script) solution

It's important not to confuse Java with JavaScript. They're thoroughly
different languages, one of which requires a virtual machine (Java), and the
other of which requires a host environment (usually a browser) that supports
a JavaScript engine. Neither of these work within the Flash Player plug-in
alone. The Adobe Integrated Runtime (AIR) supports JavaScript, but it
doesn't sound like you're talking about an AIR application here.

> I am hoping someone can help me develop a work around
> solution to read HTML within my Flex/Flash application.

I'll try. :)

> I have created a window within Flex that contains HTML text. I
> want my users to be able to click anywhere on the text and in turn,
> I want the Flex application to access the embedded hypertext.

In bare-bones ActionScript, that can be handled with the TextField.LINK
event. (I do use Flex Builder from time to time, but I'm not especially
familiar with the Flex framework, so there may be other avenues in the API
to handling hypertext clicks.)

> Maybe I should say that I need the script to work on the client side
> and that I do not want to open a new window.

Sounds fine, so far.

> Instead I want to be able to embed values in the HTML and then
> when the student clicks on the hypertext, this value is made available
> to Flex.

Again, in AS3 alone, that's the TextField.LINK event.

e.g.
myTextField.addEventListener(TextEvent.LINK, linkHandler);

function linkHandler(evt:TextEvent):void {
// handle hyperlink click here
}

> I understand that much of the javascript is blocked, but is there a
> workaround solution that can accplish this?

This is the part of your question that confuses me. Do these hyperlinks
normally trigger JavaScript? Is this HTML content something created
specifically for display in Flash Player? You needn't use JavaScript at all
to be of use in ActionScript. Just use an "event" value in your anchor tag:

<a href="event:param">click me</a>

myTextField.addEventListener(TextEvent.LINK, linkHandler);

function linkHandler(evt:TextEvent):void {
if (evt.text == "param") {
// do something
}
}

Does that make sense?


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2008 Apr 22, 2008
LATEST
You solved my problem. Thank You SO MUCH!!

-----------------------------------------------------------------------
<a href="event:param">click me</a>

myTextField.addEventListener(TextEvent.LINK, linkHandler);

function linkHandler(evt:TextEvent):void {
if (evt.text == "param") {
// do something
}
}
-----------------------------------------------------------------------

This was the solution I was looking for.
Thanks Again -CoderAmungus
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines