Reset text and go to the specific frame as3 - actionscript-3

I want to reset the text whenever I have pressed a button and after that it will go to the specific frame where I already labeled it. However, the text won't reset even though I put the reset text before gotoAndStop();
How can I solve this?
Here is the code that I am using:
payment_button.addEventListener(MouseEvent.CLICK, onClickPayment);
function onClickPayment(e:MouseEvent):void
{
if (myText1.text == "")
{
trace('Cannot proceed! There is no items in your shopping bag.');
}
else
{
myText1.text = "";
gotoAndStop("purchased");
}
}
Thank you!
Your answer much appreciated!

It sounds like you are changing the frame of the MovieClip containing the textfield. If so, then if the new frame and the current frame have different keyframes that contain the textfield, the text in the textfield will be set back to the default, regardless of whatever changes you make to it in this code, when you return to the first frame.

Related

What is this, and why is it happening?

So I have been working on my final project for the semester for my Computer Systems class, and we have been tasked to make a game using Flash and ActionScript 3.0. I've pretty much completed everything but I have come across an extremely strange occurrence of Flash CS6 being silly. I am moving a MovieClip up and down depending on a selected index, however, the image leaves 'residue of it's footprints' behind and also moves. I have tried hard to look for an answer as to why this is happening, but I don't know what it's called, or how to appropriately explain it - I'm coming from an area where one must program graphics, not just simply, drag and drop.
Below are pictures as to what I've come across, but first the code I'm using:
function updateThemeScreen():void {
button_selection.y += (selectedPositions[selectedTheme] - button_selection.y) / 2;
}
function attemptThemeChange(mxP:Number, myP:Number):void {
if(objectContains(theme_darkness, mxP, myP)) {
selectedTheme = 0;
} else if(objectContains(theme_halloween, mxP, myP)) {
selectedTheme = 1;
}
}
As you can see in the final image, it has copied half of itself and left it at the last button, which is strange, and shouldn't happen...
Link to the SWF zipped up with the required AS3 classes: Dude, RUN
So it seems that I have magically fixed this problem by hiding the buttons and showing them all in one frame. I don't know what this problem is or why it does it, but to fix it, you just need to hide and show the affected components - yes, in one frame:
function hideShow(object:MovieClip):void {
object.visible = false;
object.visible = true;
}

Adobe Flash ActionScript 3 Slide linking and rollover effect

I have a slideshow that is fading through and each Slide links to a different page. Have a simple text rollover effect I activate with AS3 so when the slide is rolled over the text changes color.
I can get it to work with just one slide but I can't get it to work when I add 3 more slides
inv_btn.addEventListener(MouseEvent.CLICK, buttonHandler);
inv_btn.addEventListener(MouseEvent.MOUSE_OVER, rollOver);
inv_btn.addEventListener(MouseEvent.ROLL_OUT, rollOut);
function buttonHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.hautepets.net/pages/grooming.php"));
}
function rollOver(event:MouseEvent):void {
rollText_1.gotoAndPlay("over");
}
function rollOut(event:MouseEvent):void {
rollText_1.gotoAndPlay("out");
}
Then add the code 3 more times but change instance names and also move the button for the next slide to another key frame. Not sure this is necessary but I also tried it with out doing this.
I use the exact same code I just change instance names on the new slide and in the code like so:
inv_btn2.addEventListener(MouseEvent.CLICK, buttonHandler2);
inv_btn2.addEventListener(MouseEvent.MOUSE_OVER, rollOver2);
inv_btn2.addEventListener(MouseEvent.ROLL_OUT, rollOut2);
function buttonHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.hautepets.net"));
}
function rollOver2(event:MouseEvent):void {
rollText_2.gotoAndPlay("over");
}
function rollOut2(event:MouseEvent):void {
rollText_2.gotoAndPlay("out");
}
any ideas of what I am doing wrong?
you need to declare these instances in the first frame, even if you don't use them
just put inv_btn2 and rollText_2 also to first frame, it will solve the problem and use visible = false/true; to show/hide them on different frames or you also can put them out of stage on first frame.

How to make part of a text in a dynamic text field link to another frame just like hyperlinking to an html page?

I have a quite long classic text in a dynamic text field, with an UIScrollBar to scroll it. It has many references inside, part to sites in the web, part to other texts that I distributed in different frames of a movieclip with the text field inside. I have no problem linking to external websites from inside the text using the link and target fields in the properties panel. I have no problem using buttons to link to specific frames using functions with the gotoAndStop method. But I can't navigate to specific frames from selected words inside the text. Actually, I can't even navigate to files inside my computer using the link and target fields in the properties panel. Html tags are not being rendered, even with the "Render text as html" button clicked. I can't change the text to static because of the scroll bar. I can't also use invisible buttons behind the words because the scrolling would make them out of place. I don't see how a var could help me, cause it makes the text field show only the selected words. Anchors seem not to help also, since I can't target a file, but only http. Any ideas will be very welcome.
What you want is possible. But it comes with a little drawback thanks to a flash textfield bug. First your textfield text needs to be html text and also selectable. Then look here:
Textfield link event
public function TextField_event_link() {
myMP3 = new Sound();
var text:TextField = new TextField();
text.autoSize = TextFieldAutoSize.LEFT;
text.multiline = true;
text.htmlText = "Hello this is my little site. Click herefor the imprint. And here for the about page. And if you're coming so far, also here for the exit";
list.addEventListener(TextEvent.LINK, linkHandler);
addChild(list);
}
private function linkHandler(linkEvent:TextEvent):void {
switch(linkEvent.text)
{
case "imprint":
//display imprint
break;
case "about":
//display about
break;
case "exit":
//exit
break;
}
}
You can compare the event name in the handler and do your magic. If your text is not selectable this will not work. Dono if Adobe has fixed that issue with the latest player but this bugged me for years!

AS3 Dynamic text box over button

In AS3 I have a button on the stage and above it I create a textbox box dynamically with code.
My problem is that the area that is under the text (i.e. that part of the button) is no longer clickable.
I have set:
tBox.selectable = false;
but that doesn't solve it.
Any ideas
Season greetings,
Luben
Use InteractiveObject.mouseEnabled:
textField.mouseEnabled=false;
If you set component.visible to false it does not interact with the user.
So, if you set tBox.visible = false then it will be invisible and the button will become clickable. Just a thought, but overlapping components is really bad UI design. If you have space on your stage, you should consider keeping them separate
The problem is that text field (despite it's transparent) is lying over button. To make click on button possible you have to be sure that button is in front of text. Take a look at AddChildAt method of DisplayObject. Objects with greater position index are lying over objects with lower position index. So all you need is to make sure that button has greater index:
container.addChildAt(button, 1)
...
container.addChildAt(text, 0)
P.S.: you may embed button dirrectly into text field using html <a href="javascript:..."><img src="link_to_image"><a/> or something like that.

Clicking Text Element in Tween Halts Animation

I've been having some trouble with tweens. Here's a description of my usage:
I have a system where a textbox is the child of a movieclip. When you click the "Next" button, the movieclip fades to 0-alpha and upon completion, the text in the textbox is changed (to the next index in an array) and it tweens back in to 100-alpha. This makes a nice transition through the text.
My issue is that sometimes it doesn't tween back in, only out, leaving the user with an empty box where text should be.
However, I'd asked this question previously with the thought that it was "Timing out". Now, after significant testing I realised that it only happens if I click or select some of the text on the text box. Could it have something to do with this text selection intefering with the changeText function below... (it's the same text box, just the text changes).
Has anyone else experienced similar faults?
CODE:
function changeClick(e:MouseEvent):void {
if (e.currentTarget==btnRight) {
newDirect="right";
} else {
newDirect="left";
}
if (newDirect=="right") {
if (pageTotal!=pageCurrent) {
tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
}
} else {
if (pageCurrent!=1) {
tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
}
}
}
function changeText(e:TweenEvent):void {
var newText:String;
var pageCurrentConstant:int=pageCurrent;
if (newDirect=="right") {
for (var i=0; i<=(pageTotal-1); i++) {
if ((pageCurrentConstant-1)==i) {
if (i!=pageTotal-1) {
newText=pageText[i+1];
pageCurrent++;
} else {
newText=pageText[i];
}
}
}
} else {
for (var j=0; j<=pageTotal; j++) {
if (pageCurrentConstant==j) {
if (j!=0) {
newText=pageText[j-2];
pageCurrent--;
} else {
newText=pageText[j];
}
}
}
}
b_textB.htmlText=newText;
tweenText=new Tween(b_textB,"alpha",Strong.easeOut,0,1,.5,true);
drawWidget();
}
changeClick is initiated by either btnRight or btnLeft to navigate through the text
Try disabling the text selection, with b_textB.selectable = false
You will be able to quickly rule out the possibility of a selection issue. But the sometimes in your question strongly indicates that's what the issue is.
If you need the text to be selectable when it's visible, just switch it off and on at the start and end of the tweens.
Hope this solves it.
Oh by the way, here's a list of several completely free alternatives to the Tween class... (Greensock's Tween packages are not free.)
Between AS3
Desuade Motion ... This one in particular is awesome.
Tweener
Tweensy
Twease
Update...
The only way you can solve this and allow the user to select the text, is to make a duplicate textfield that's selectable, and toggle visible off for this when the tween begins and on again when it ends, the alpha property on the effected textfield will then work properly.
Pretty kludgy I know, but it will get the effect to work, and allow the user to select the text when it's visible.
You may also try to wrap the original textfield in a Sprite and do the alpha Tween on that instead, however I don't guarantee that will be a 100% fix.
The standard Tween class is kind of stupid in many situations. When using it, you have to be careful that you don't overwrite or remove its instance, as the Garbage Collection could start then. In the same way it always requires you to specify a start value which can lead to disrupting behaviour in the animation.
I'm not exactly sure what exactly your problem is, and with that less code it is hard to reproduce it (you might want to provide a full working example code if you still experience the problem). However I suggest you to try out a different tweening framework. I for myself have made very good experience with Greensock's TweenLite. It might have a weird syntax (at least I could imagine a better one), but in general it works really well, and I have solved very many problems with the standard Tween class by simply using TweenLite instead.