A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: quick code re-write (as2-as3)

  1. #1

    quick code re-write (as2-as3)

    Let me preface my post by saying that I am not an AS writer. I find it much easier to come here and get the stuff I need from all of you AS geniuses. I have this little piece of script that I need to re-write in AS 3. I'm using the FlashEff plugin on a banner ad, but need it re-write the get URL portion of the button in AS3 in order for it to work. Here's that code:

    on (release) {
    getURL(_root.clickTAG, "_blank");
    }

    Can someone show me the AS3 version of this? Thanks!!!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You'll have to move the code from the instance to some other place. Possibly the root. Replace <instancename> below with the actual instance name.

    Code:
    <instancename>.addEventListener(MouseEvent.MOUSE_UP, handleMouse);
    
    function handleMouse(event:MouseEvent):void{
      navigateToURL(new URLRequest(MovieClip(root).clickTAG), "_blank");
    }

  3. #3
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Well that is most likely on the button which you cant do in AS3. You have to put code on the time line or in classes.
    buttonName.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    function mouseUpHandler(evt:MouseEvent){
    navigateToURL(new URLRequest(root.clickTAG),"_blank");
    }

    or something close to that.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  4. #4

    Still no go

    I tried to use your code:

    urlbutton.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    function mouseUpHandler(evt:MouseEvent){
    navigateToURL(new URLRequest(root.clickTAG),"_blank");
    }

    but still no go. It gives me this error:
    1119: Access of possibly undefined property clickTAG through a reference with static type flash.displayisplayObject.

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You've got to cast root to MovieClip to access properties that are not defined in DisplayObject. See my code above. That's really all you should have to change.

  6. #6
    I totally appreciate your help! The problem I'm having is that this is a banner ad that is going on someone else's site, so I can't do anything at the root level. I have no idea what I'm doing with AS3.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You don't need to change anything on the root level. Casting is that part that looks like this:
    Code:
    MovieClip(root).clickTAG
    It tells the compiler to treat root as a MovieClip rather than a DisplayObject so that you can access dynamic properties.

  8. #8

    sweet!

    Now I get it. I'll put that in there and see what happens. Thanks again for your help!

  9. #9
    Hot Damn!!! It worked! Thanks so much!

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