A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: image loaded trough htmlText

  1. #1
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425

    image loaded trough htmlText

    Sorry about the obscure name.
    Here's the problem; let's say you got the following code and
    an image named "img.png" in the same directory.

    code:
    import flash.text.TextField;

    var t :TextField = new TextField ();
    t.htmlText = "<a href=\"#\"><img src=\"img.png\" id=\"myImage\"></a>";
    addChild ( t );



    The textfield will automatically load in the image and embed it.

    1) How can I get a reference to the image? (To be able to handle IOErrors for instance).
    I checked the livedocs and came up with this (TextField - htmlTex):
    the id attribute - Specifies the name for the movie clip instance (created by Flash Player) that contains the embedded image file,
    SWF file, or movie clip. This is useful if you want to control the
    embedded content with ActionScript.
    Sounds like exactly what I need, only thing is - how does it work? There's no documentation whatsoever.

    2) The html-link placed around the image tag won't work as you might
    expect. Only the border around the image is a button, the actual image
    lies over the hitarea (Check out this example ). If I solve the first
    problem I'll probably be able to find away around this though.

    Thanks in advance
    // Mazapán, my portfolio

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    In Flash 8 you could reference to the image using

    t.myImage;

    but that does not seem to work any more in AS3, since myImage is not a property or method of the TextField. Either the statement in the Live docs is wrong or there is a different way of doing that.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Different way

    t.getImageReference("myImage");

    You can give button mode to the image in this way:

    var myImage:Sprite = Sprite(t.getImageReference("myImage").root);
    myImage.buttonMode = true;
    Last edited by cancerinform; 01-20-2007 at 07:58 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Thank you cancerinform! You have truly saved the day(week)!
    I've already started a script that cuts up the text into multiple text fields
    and places them around images, but I'll happily discard that.
    // Mazapán, my portfolio

  5. #5
    Junior Member
    Join Date
    Jan 2007
    Posts
    2
    t.myImage

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    see above
    - The right of the People to create Flash movies shall not be infringed. -

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