Anna Smother
Anna Smother

Reputation: 320

html data in a string make clickable html link AS3/Flex

I have a scenario that I get an string with html data, this is not just html data it's an email (outlook) saved as an html file and dropped in the string.

Now this string needs to be formatted to an html document and should be a clickable link in a datagrid. So when I click on the link, the HTML document should pop-up and should gave me a nice HTML page that is readable for the normal users. I hope it's a bit clear what I want o_0.

I don't know where to start.

You can download the example html from here: http://www.mediafire.com/?b2gfwymw70ynxir

Thanks!

---edit

Hopefully I can explain it a little bit better. I need to create an link and when they click on it they get an HTML page. The string variable has HTML data in it, to be precise, the source data of the HTML example above. example: public var html:String = source_code_of_example_file;

The entire source code of the HTML page is in my variable html. Now I need to make this an link and when they click on it, they will get the html page (as pop-up) on the fly.

Upvotes: 0

Views: 1128

Answers (3)

uiscedan
uiscedan

Reputation: 11

You can use the htmlText property and then specify a CSS to perform the proper formatting:

<mx:TextArea id="resourceText" height="100%"  width="100%"
            styleName="resourceText" editable="false" 
            styleSheet="{resourceStyleSheet}" htmlText="{html}"/>

To read in the style sheet I declare it in the model:

public var resourceStyleSheet : StyleSheet;

It gets read in from an external file:

private function loadCSS():void {           
   var urlLoader:URLLoader = new URLLoader();
   urlLoader.addEventListener(Event.COMPLETE, cssCompleteHandler);
   urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

   try {
     urlLoader.load(new URLRequest("folder/base-html.css"));
   } catch (error:Error) {
     Alert.show("Unable to load requested document.");
   }            
}

private function cssCompleteHandler(event:Event):void {
  // Convert text to style sheet.
  var styleSheet:StyleSheet = new StyleSheet();
  styleSheet.parseCSS(URLLoader(event.currentTarget).data);
  // Set the style sheet.
  model.resourceStyleSheet = styleSheet;
}

private function ioErrorHandler(event:IOErrorEvent):void {
  trace("ioErrorHandler: " + event);
}   

This will get it into the model, but then make sure resourceStyleSheet is bindable when you use it (I actually set a bindable variable on the view that I set to the model value.

Upvotes: 1

Chris Ghenea
Chris Ghenea

Reputation: 12943

There is no easy way to display HTML in a flex web application(this is a web application, right?). Like Xavi Colomer said you can use the Flex Iframe but is terribly slow, it requires you to change the display mode for your swf to opaque and this can cause more problems, depending on your application.

You could open a new page in the browser that will be used to display the HTML. Something like:

http://www.yourcooldomain.com/bla/displayTheHtml.php?oneTimeId=jhsfg765437gro734

More info on how to do this from flex here.

On the other side(server) I assume that you keep this html messages on a database(?) so displaying them using php(or whatever you are using :P) should be easy.

If you are gonna choose this path be careful about the security: oneTimeId in

displayTheHtml.php?oneTimeId=jhsfg765437gro734

should really be an one tyme only id.

Upvotes: 0

Mc-
Mc-

Reputation: 4056

It's not really clear what you want to do.

If your problem is you need to show HTML formatted text in flex there is a component which can do this

http://code.google.com/p/flex-iframe/

-- update after edit

If your intention is to open a html popup once the user clicks on the link you could use ExternalInterface to call a javascript function to do this.

Hope it Helps

Upvotes: 0

Related Questions