Question

I have a flash as3 file, and I'm importing an HTML file that contains this link:

<a href="purchase.php?lang=0&"><img src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" id="paypal_button"></a>

and I cannot for the life of me figure it out, I've looked everywhere.

There were a couple of forums that suggested:

function onTicketLoad():void {
if(paypal != null && this.contains(paypal)) {
    removeChild(paypal);
}
var imgLoader:DisplayObject = content_text.getImageReference("paypal_button");
//imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onHtmlImageLoaded);
paypal.addChild(imgLoader.content);
}

function onHtmlImageLoaded(e:Event):void {
    e.target.removeEventListener(Event.COMPLETE, onHtmlImageLoaded);

    paypal.addChild(e.target.content);
    paypal.buttonMode = true;
    paypal.useHandCursor = true;
    addChild(paypal);
}

(that example is fragmented as all hell, I just included it to illustrate what I'm trying to do)

Basically I think I need to load the image into the getImageReference method... but I'm so lost... any help would be appreciated!

Was it helpful?

Solution

If you are going to use the < img > tag in an htmlText box, "you must set the text field to be multiline and to wrap text"

I tried it, and it works fine for me. It loaded the image and the link worked too. Here is my code:

import flash.text.TextField;

var labelText:String = '<a href="purchase.php?lang=0&"><img src="https://www.paypal.com/en_GB/i/btn/btn_buynowCC_LG.gif" id="paypal_button"></a>';
var label:TextField = new TextField();
label.border = true;
label.multiline = true;
label.wordWrap = true;
label.width = 200;
label.height = 100;
addChild(label);
label.htmlText = labelText;

My example uses pure AS3, but it should be exactly the same as selecting "multiline" and "wordwrap" from your textfields properties panel.

OTHER TIPS

I've found creating links on <img> tags in TextFields in Flash can be problematic.

I spotted the issue has been reported on the adobe bug tracker here:

http://bugs.adobe.com/jira/browse/FP-2146

Once as a workaround I created a separate swf file the exact same size as the image and embedded that instead (i.e. a 160x47 stage and a MovieClip/button with a clickable link using navigateToURL). Basically you can embed swf files within TextFields the same way as images.

It's not ideal but it did seem like a decent compromise considering the swf 'button' can now be used and laid out in more or less the same way as you would have used the <img> tag.

AIR (Mobile) ignores IMG tags for security apparently... useless in my opinion. Adding the fact the TextFlow is not recommend or supported for that either in Mobile, and many other fruit less attempts to get an IMG tag to render is beyond challenging so far. I'll wager nearly impossible with the given components (in AIR Mobile land of course, which is not well documented and conflictive with online sources around the issues, so it is unclear and confusing being fresh out of beta).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top