A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 TextField button problem <-- Dont know where this should be posted

  1. #1
    Junior Member
    Join Date
    Jul 2010

    AS3 TextField button problem <-- Dont know where this should be posted

    I am trying to create a hyperlink in my text field that when clicked will take you a website target a _blank page.

    I have created a text field and input the website through xml - src, I put the text field inside a movieclip - link, i created a sprite and put that in the movieclip. However anytime that I try to click it, no matter the configuration I get one of two errors:

    Error #1069: Property loader not found on flash.text.TextField and there is no default value.
    ^^Is the most common

    The other one is I believe Error #1010 Can not target and object of null reference?? Something along those lines.

    My Code:
    var link:MovieClip = new MovieClip();
    var anchor:Sprite = new Sprite();
    anchor.graphics.drawRect(265, 235, 690, 20);
    anchor.alpha = thumbFadeOut;
    link.anchor = anchor;
    var urlFont:TextFormat = new TextFormat();
    urlFont.size = 16;
    urlFont.color = 0x0000ff;
    urlFont.font = mf.fontName;
    urlFont.bold = true;
    urlFont.align = TextFormatAlign.LEFT;
    var urlArea:TextField = new TextField();
    urlArea.embedFonts = true;
    urlArea.defaultTextFormat = urlFont;
    urlArea.antiAliasType = AntiAliasType.ADVANCED;
    urlArea.wordWrap = true;
    urlArea.width = 690;
    urlArea.height = 20;
    urlArea.y = 265;
    urlArea.x = 235;
    urlArea.text = e.currentTarget.link;

    productBox.addEventListener(MouseEvent.CLICK, closeProductBox);
    productBox.buttonMode = true;
    link.buttonMode = true;
    link.addEventListener(MouseEvent.CLICK, gotoPage);

    function closeProductBox(e:MouseEvent):void {
    trace("clicked product box")
    Tweener.addTween(productBox, { alpha:0, time: 1, onComplete:function(){removeChild(productBox)}});
    scroller.addEventListener(Event.ENTER_FRAME, moveScrollerThumbs);

    function gotoPage(e:MouseEvent):void {
    trace("going to " + e.target.loader.parent.parent.link);
    var pageAdd:String = new String(e.target.loader.parent.parent.link);
    var web:URLRequest = new URLRequest(pageAdd);
    navigateToURL(web, "_blank");

    All that I am trying to do is put some text into a movie clip that can be made into a hyperlink button. The http:// link is pulled from an xml file.

    What it is, is a product slide show that when you click on the image a text field appears inside a white box that gives a description.

    There is a large white box with an image of the product on the left, a title top right, description in the middle right, hyperlink to manufactor on the bottom left.

    The code maybe very erratic but I am very novice to actionscript.

    This is a link to the entire file: http://cl.ly/b4e06afa97f9350c945a

  2. #2
    Join Date
    Apr 2003
    1st error: Because your urlArea TextField is physically overlapping your MovieClip link, urlArea has taken priority over it. As a result, goToPage ends up originating from urlArea instead, which is why the first error message talks about TextField - Error #1069: Property loader not found on flash.text.TextField.

    2nd error: Even if link is properly referenced via e.target, MovieClip does not have the property loader. Unfortunately loader is undefined, hence when you try to access loader.parent.parent it is completely undefined, giving Null Reference error.

    To fix this, Just register the MouseEvent to TextField urlArea instead. Since you typed urlArea.text = e.currentTarget.link;, you can use urlArea's text as the URL instead.

    Actionscript Code:
    urlArea.addEventListener(MouseEvent.CLICK, gotoPage);
    Actionscript Code:
    function gotoPage(e:MouseEvent):void {
        trace("going to " + e.target.text);
        var pageAdd:String = new String(e.target.text);
        var web:URLRequest = new URLRequest(pageAdd);
        navigateToURL(web, "_blank");

    As tested it launches a kangaroo picture in my Firefox , and that's a pretty nice gallery slideshow btw. Hopes this helps you understand how Flash works.

    PS: In future to avoid TextField interfering with Mouse Events, use the mouseEnabled = false; property on TextFields that you do not intend to register Mouse Events for.
    Last edited by cardin; 07-16-2010 at 01:37 AM. Reason: Fixed typo in code snippet
    My DeviantART gallery of drawings and games.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Cardin -
    Thank you very much for your help. I changed the lines of code that you suggested near as I can tell everything is working great. It just isn't yet changing my mozilla page. But I have always had this problem, until I get it uploaded to a server.

    Any Ideas on that one?


  4. #4
    Junior Member
    Join Date
    Jul 2010
    I need a little bit more help. We have the link working perfectly, thank you, however when I mouse over the link it stays with a text cursor, I need it to switch over to a finger cursor?

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