Skip to main content
juli_h
Participant
August 24, 2015
Question

How to link to a webpage via a class in Flash Professional?

  • August 24, 2015
  • 1 reply
  • 452 views

Hey there!

I'm not a complete beginner since I have worked with the program for some months now and creating a button via the action panel hasn't been a problem. But I guess I'm still a noob because this time my client needs the button/clicktag to be integrated via a document class so clicks can be counted etc. and I just can't get it to work.

Here are the specs I got from my client for Actionscript 3:

var clicktag:String=root.loaderInfo.parameters.clicktag;

var target:String=root.loaderInfo.parameters.target;

function onClic(pEvt:Event):void {

var redirect:URLRequest = new URLRequest( clicktag );

navigateToURL (redirect, target);

}

Button_btn.addEventListener(MouseEvent.CLICK, onClic);

Well that's looking alright...

Now for my script so far... My button on stage is called button_1 the class is called Btn:


package {

    import flash.events.*;

    import flash.display.*;

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    public class Btn extends MovieClip {

        public function Btn() {

            var clicktag: String = root.loaderInfo.parameters.clicktag;

            var target: String = root.loaderInfo.parameters.target;

            button_1.addEventListener(MouseEvent.CLICK, onClic);

            function onClic(pEvt: Event): void {

                var redirect: URLRequest = new URLRequest("http://www.example.com");

                navigateToURL(redirect, target);

            }

        }

    }

}


For some reason this does not work. The button is recognized as an interactive panel but the link itself is not executed.

I'd really appreciate any suggestions about a solution. Maybe I just overlooked something?


Thanks in advance!

(I'm executing in Actionscript 3 and Flash Player 10.3 and there is no compiler error coming up when testing the scene)

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
August 24, 2015

I believe your redirect variable is mis-assigned and possibly your target as well.

Normally the value that is read in from the root.loaderInfo.parameters.clicktag is what gets assigned where you show "redirect".  In your case, unless I am missing something, you are using redirect as an internally defined variable.

The target variable is normally a window specification such as "_blank" or "_self" and I cannot determine that is the type of value that it is based on what you show.  It seems a bit odd that it would be defined outside the program, but is possible.

juli_h
juli_hAuthor
Participant
August 24, 2015

First off: Thank you so, so much for the quick answer.

Now that you mention it, it really does seem weird. I thought the redirect and target variables were written this way because they want to count the clicks somehow that way... So for the window specification they're probably doing that external... At least I guess so.

So let me summarize what you're saying just to be sure: the "redirect" is in conflict with the clicktag variable, right? The Value that should be read from root.loaderInfo.parameters.clicktag is the webpage's adress.

So it should say something like:

(...)

public function Btn() {

            var clicktag: String = root.loaderInfo.parameters."http://www.example.com";

            var target: String = root.loaderInfo.parameters.target;

            button_1.addEventListener(MouseEvent.CLICK, onClic);

            function onClic(pEvt: Event): void {

                navigateToURL(clicktag, target);

            }

        }

(…)


I'm sorry if this is wrong in a noob kind of way (which it probably is because this is still not working). I'm just stressing out a bit right now and going back to try and error methods which is probably not the right way to solve this...

Again, thanks a lot!!

Ned Murphy
Legend
August 24, 2015

The clicktag parameter would not be assigned as you show it.  It will be extracted from the html code in the web page.  It should not be hardcoded into the Flash file at all.  The html code that embeds the swf in the web page should include some parameters, namely "target" and "clicktag"

Note:  I am not a clicktag experienced person... my response reflects my understanding from some number of years helping people with clicktag issues every so often