?
Solved

Using text in AS3 to gotoAndPlay a frame label

Posted on 2011-03-22
9
Medium Priority
?
1,335 Views
Last Modified: 2012-05-11
Hello, I'm working in Adobe Flash CS5/AS3 for the Mac.  I was wondering how I can use TLF or dynamic text to "gotoAndPlay" a frame label in my document.  There is an option to specify a link URL under the "Link" field, however, I need the text to jump to a frame label when it is clicked on, NOT open up a URL.

This text is also located within a movieclip that is already on the main timeline.  It would need to communicate with the main timeline and jump to a frame label on there.

I've worked around this before by creating buttons that jump to a different frame when they are clicked on, but I figured there's got to be an easier way to do this via text.

Thanks in advance.
0
Comment
Question by:DEPAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:DEPAdmin
ID: 35198059
I noticed that the 2 links you posted are in reference to navigating to other html web pages.  I need to navigate to a "frame label" in my document on the main timeline from the inside of a movieclip.  Is it possible to do this?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35198146
I posted the links to show you how TextEvent works. Now in the event handler function user your script instead of navigateToURL.

Use gotoAndPlay("labelName");

Warm Regards
Deepanjan Das
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DEPAdmin
ID: 35198506
I'm completely lost (I guess I should have mentioned I'm relatively new to programming lol).  I honestly don't understand the difference between public and private class, and I get the Syntax Error "package is unexpected."

Here's a break down of what I am trying to do.

- I have a text field on the stage already (not sure if it should be dynamic, or TLF text) with the instance name of "section1_txt", and the text on the stage reads "Section 1."
- When this text field is clicked on, I want it to gotoAndPlay the frame label named "s1summary" on the timeline.

Seems easy enough, but I wasn't sure if this was possible, or if I need to create a button instead to do what I need it to do.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35199396
Hope this helps :)
import flash.events.TextEvent;

field.htmlText="This is a test.";
field.addEventListener(TextEvent.LINK,clickin);

function clickin(evt:TextEvent):void
{
    trace(evt.text);
    gotoAndPlay("labelName");
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:DEPAdmin
ID: 35199508
I did try your code and it does place "This is a test" on the stage, however, it does not do anything when you try to click on it.

I was supposed to replace "field" with "section1_txt" correct?

Also, what kind of text should it be (TLF, dynamic, static, etc.)?

Thanks.
0
 

Author Comment

by:DEPAdmin
ID: 35199776
I played around with the code and got the following to work (when the user clicks on "Section 1" it takes them to the frame label "s1summary"...I changed it to a MouseEvent and it appears to work):
import flash.events.TextEvent;

section1_txt.htmlText="Section 1";
section1_txt.addEventListener(MouseEvent.CLICK,clickin);

function clickin(event:MouseEvent):void
{
    gotoAndPlay("s1summary");
}

Open in new window

0
 
LVL 17

Accepted Solution

by:
deepanjandas earned 2000 total points
ID: 35199851
What you did is made the whole text clickable.
TextEvent goes with when a word in the whole sentence needs to be only linked.

Like this:
import flash.events.TextEvent;

field.htmlText="This is a test <a href='event:labelName'>link</a>.";
field.addEventListener(TextEvent.LINK,clickin);

function clickin(evt:TextEvent):void
{
    trace(evt.text);
    gotoAndPlay(evt.text);
}

Open in new window


Warm Regards
Deepanjan Das
0
 

Author Comment

by:DEPAdmin
ID: 35200029
Ah OK, I get it now.  I tried out your code and that does work also.

Thanks for your help :)
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question