A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: TextField + a href + img

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Posts
    129

    TextField + a href + img

    Hi,
    I've stucked with a really weird behavior of TextField.

    Look at this sample:
    PHP Code:
    var myField:TextField = new TextField();
    var 
    format:TextFormat = new TextFormat();
    format.font "Arial";
    myField.defaultTextFormat format;
    myField.width myField.height 300;
    myField.embedFonts true;    // with false it works
    myField.selectable false;
    myField.htmlText "test this image and you'll see: <a href='http://www.google.com'><img src='image.jpg' width='120' height='124'/></a>";
    addChild(myField); 
    My goal is to have a text field with picture which works as URL link. It works fine in case that font isn't embed, once embedFonts is true then picture is dead. See attachment where is the source code and output html.
    Thanks
    Attached Files Attached Files

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I don't know the reason, but it works when you click twice.
    http://flashscript.biz/test/FK/test.html
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Posts
    129
    Hi,
    thanks for your attempt!
    Did you realize in which case it happens? Only when selectable is true and when between first and second click some part of text is (or was?) selected. Really strange.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I tested in Flash CS4 with Player 10 and the same. I also noted the text selection. You might want to inform Adobe about this as a Bug.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    2
    I had the same problem and with a quite difficult and demanding client, so i had to figure this out. And i found a not so simple solution but it works. Flash makes movieclips of every <img> in a textfield so they have the same properties as all movieclips and so does onRelease-function work with them. just add id-property to the <img> -tag. It will be the name of the movieclip Flash creates. So you can add the link to this property (of course with some decoding 'cos Flash doesn't allow / . etc in movieclip names). After the textfield has loaded all the <img>'s, go through this textfield-instance and search for movieclips that have an address as their name. Create onRelease-function to all of these with getURL-command. I can post a more accurate explanation if necessary.

  6. #6
    Senior Member
    Join Date
    Apr 2006
    Posts
    129
    Hi,
    could you send more informations about your solution? As far as I know TextField isn't DisplayObjectContainer so it cannot store any movieclips.
    Thanks

  7. #7
    Junior Member
    Join Date
    Jun 2009
    Posts
    2
    If your <img>'s ID is for example "imglink" and your textfield is on the root timeline named "textcontent", go through the textfield using this code:

    for (i in _root.textcontent) {


    }

    i is the name of the movieclip inside the textfield -object. So if i = "imglink" you can use:

    _root.textcontent[i].onRelease = function () {}

    This will create an onRelease -function to the movieclip created by <img> -tag. onRelease can be created only if the movieClip has loaded fully, so you have to create a timer function or onComplete-function to check if the movieClip is ready.

    Of course you have to also input the address to the ID, so you can use "imglink&&&enteraddresshere" and strip the string using "&&&" as the delimiter. Another problem is that movieClip names cannot contain characters like : / and so on, so you have to replace them with &slash; etc. and decode them in Flash after. Hope this helps.

  8. #8
    Senior Member
    Join Date
    Apr 2006
    Posts
    129
    From what you wrote this probably works in AS2. I've tried the same in AS3 (this forum) with no success. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center