A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Navigate to URL help

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    17

    Navigate to URL help

    So I'm using the code below so that if someone clicks on a movie clip, it takes them to a webpage:

    MovieClipName.buttonMode = true;
    MovieClipName.addEventListener(MouseEvent.CLICK,f) ;

    function f(e:Event){
    navigateToURL(new URLRequest("http://www.URL.com"), "_self");
    }

    This is working absolutely perfect for 2/3 movie clips in my library. However, when I try to apply the code to a third movie clip in my library using the exact same code, I get the error: 1120: Access of undefined property MovieClipName3.

    I don't understand. The exact same code is working flawlessly for MovieClipName1 and MovieClipName2. Why do I get an error when I try to apply it to MovieClipName3? Thanks in advance!

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    Not sure exactly, just recreated using your code and it worked out fine. Maybe something else is misfiring in your source code. Post a part of your source FLA for more help. Also, can you be more specific about how you're "applying" the code.
    Last edited by Steven FN; 10-26-2014 at 03:14 AM.

  3. #3
    Junior Member
    Join Date
    May 2007
    Posts
    17
    Yeah this one is confusing me. Let me try to be even more specific. I have 3 movie clips in my library titled "1" "2" and "3." All 3 of these clips are themselves inside of another movie clip called "Root" The root movie clip fades between movie clips 1, 2 and 3 in a cycle. I want the user to be able to click 1, 2, and 3 and have that action take them to a webpage. On the first frame that "1" is visible inside "Root," I apply this code on a separate layer called "actions":

    1.buttonMode = true;
    1.addEventListener(MouseEvent.CLICK,f1) ;

    function f1(e:Event){
    navigateToURL(new URLRequest("http://www.URL1.com"), "_self");
    }

    Perfect! Every time "1" is in view, I can click it and it takes me to the URL. Next, I add a new keyframe to the "actions" layer as soon as "2" becomes visible and add the following code:

    2.buttonMode = true;
    2.addEventListener(MouseEvent.CLICK,f2) ;

    function f2(e:Event){
    navigateToURL(new URLRequest("http://www.URL2.com"), "_self");
    }

    Again, perfect! "1" still works and now "2" takes me to URL 2 when I click on it (exactly what I want). So at this point I add a new keyframe to the "actions" layer when "3" becomes visible and add the following code:

    3.buttonMode = true;
    3.addEventListener(MouseEvent.CLICK,f3) ;

    function f3(e:Event){
    navigateToURL(new URLRequest("http://www.URL3.com"), "_self");
    }

    Same exact thing that I did for "1" and "2" except this time it does not work. I get the error: 1120: Access of undefined property 3. This makes no sense

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    It generally means you have not declared or named something properly.

    Attch your *.fla for further scrutiny

  5. #5
    Junior Member
    Join Date
    May 2007
    Posts
    17
    Quote Originally Posted by fruitbeard View Post
    Hi,

    It generally means you have not declared or named something properly.

    Attch your *.fla for further scrutiny
    How do I upload a .fla here?

  6. #6
    Junior Member
    Join Date
    May 2007
    Posts
    17
    Figured out how to attach .fla

    ASError.fla Anyways...my project is somewhat private so I made a sample .fla of what I'm trying to do. For this one, none of the movie clips seem to be working.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    For starters, the (e:Event) should be (e:MouseEvent)
    PHP Code:
    Clip1.buttonMode true;
    Clip1.addEventListener(MouseEvent.CLICK,f1);

    function 
    f1(e:MouseEvent)
    {
        
    navigateToURL(new URLRequest("http://www.google.com"), "_self");

    on the timeline inside root movieclip, you have not named any of the clips, you need to give them instance names. The library name does not count, the AS Linkage name would count if you were to dynamically add them to the stage.

    You should try to stay clear of naming things the same as built in class names, ie root and try not to give library names the same as the AS Linkage name. It saves a few possible headacheds along the way.

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