• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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)

TOPICS
ActionScript

Views

359

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

Okay, okay! Got that! I teamed up with another developer. We still didn't manage to come up with a solution but now we got a compiler error which should be manageable. At the very moment the full code looks like this (I came up with the change "SimpleButton" which doesn't seem to make a difference to "MovieClip"):

package {

    import flash.display.SimpleButton;

    import flash.events.*;

    // import flash.display.*;

    import flash.events.MouseEvent;

    import flash.net.URLRequest;

    import flash.net.navigateToURL;

    public class Btn extends SimpleButton {

        // public var clicktag: String = root.loaderInfo.clicktag;

        // "http://www.example.com";

        public var clicktag: String = "http://www.example.com";

       

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

       

        public var target: String = "_blank";

       

       

        public function Btn () {

            button_1.addEventListener(MouseEvent.CLICK, onClic);

            }

       

        public function onClic(pEvt:Event):void {

            var redirect:URLRequest = new URLRequest( clicktag );

            navigateToURL (redirect, target);

        }

       

        // button_1.addEventListener(MouseEvent.CLICK, onClic);

        // myFunc();

    }

}


Apparently the variables:

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

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

are actually correct but we commented them out to be able to test the whole thing.

The error code which shows up is 1061: Call to a possibly undefined method addEventListener run through a reference with static type Block.


I'd appreciate your opinion on this since we gave up for now after not being able to solve that last error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

If that is all the code you have and the only line that adds an event listener is

button_1.addEventListener(MouseEvent.CLICK, onClic);

then I have to say that button_1 must be some object you created that has been assigned a class ID of Block.  Since I don't see that included with your import statements, maybe it needs to be added to the list.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 25, 2015 Aug 25, 2015

Copy link to clipboard

Copied

Yeah button_1 is an object on stage I created to function as the overall button. Do you mean this class? I thought this was the one I'm working on...

Bildschirmfoto 2015-08-25 um 09.13.55.png

How do I import it then?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 25, 2015 Aug 25, 2015

Copy link to clipboard

Copied

LATEST

I got it! You were right! The class ID that was assigned to my Object on stage had to go. After that I simply connected the scene to my original Script (Btn) and now everything works just fine!

Thanks a lot, Ned.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines