Jump to content


Fade in mc using actionscript


  • You cannot reply to this topic
11 replies to this topic

#1 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 04 March 2007 - 06:44 AM

G'day guys,

Trying to be as clear as possible here...

I'm hoping to have a button which the user can press, which loads an external text file (into an mc, I'm assuming) which fades in, rather than just appears instantly. I realise there's an issue with dynamic text boxes, and I've embedded the glyphs, so that shouldn't be a problem. As an aside, the button, once pressed, also causes another mc to move (which will explain the code).

Anyway, here's what I've got so far:

on (press){
		redline.number = 200
;
	loadText = new LoadVars();
	loadText.load("TEXT1.txt");
	loadText.onLoad = function(success) {
		if (success) {
			// trace(success);
			text_mc.textbox.html = true;
			text_mc.textbox.htmlText = this.myNews;
		}
	};
}

As you can see, I've got the redline moving to 200 on the x axis, and that's working fine, as is the loading of the external text file into my text_mc.textbox. The only thing I HAVEN'T managed yet is getting the text to fade in, which I'm assuming I'd do by actionscripting the alpha of the text_mc. Please help!!!!!

Cheers,

boogooloo1 :(

#2 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 04 March 2007 - 01:28 PM

Put this at the top of your actionscript
import mx.transitions.Tween;
import mx.transitions.easing.*;

Put this after you assing the text to your textfield.
var textmcTween:Tween = new Tween(text_mc, "_alpha", Strong.easeOut, 0, 100, 1.5, true);

The 1.5 is the number of seconds the tween will go for. Change that as you see fit.

#3 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 04 March 2007 - 05:29 PM

View PostPax, on Mar 5 2007, 04:28 AM, said:

Put this at the top of your actionscript
import mx.transitions.Tween;
import mx.transitions.easing.*;

Put this after you assing the text to your textfield.
var textmcTween:Tween = new Tween(text_mc, "_alpha", Strong.easeOut, 0, 100, 1.5, true);

The 1.5 is the number of seconds the tween will go for. Change that as you see fit.

G'day mate,

I probably should have mentioned that I'm also running funkysoul's mp3 player in this fla :)

Anyway, I put the first section you posted at the top of the other actionscript (which includes the mp3 stuff), but I'm not sure where to put the var code...? Do I put it in the code I already posted (which is the button's actionscript), or in the main actionscript somewhere? I've tried putting it in various places in the button's actionscript, and get this message:

Quote

The class or interface 'Tween' could not be loaded.

Thanks for your help!

;)

#4 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 04 March 2007 - 05:54 PM

If you have that code on the button, try putting the tween imports within that buttons code. But the var code right after you assign the text to the textfield, which is on the button, I believe.

Edit:

By within the button code, I mean at the very top of it before you actually have any other code. Imports should always appear before anything else.

Edited by Pax, 04 March 2007 - 05:55 PM.


#5 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 04 March 2007 - 06:41 PM

Unfortunately, if I put the tween imports at the very top, like this:

import mx.transitions.Tween;
import mx.transitions.easing.*;
on (press){
		redline.number = 200
;
	loadText = new LoadVars();
	loadText.load("TEXT1.txt");
	loadText.onLoad = function(success) {
		if (success) {
			// trace(success);
			text_mc.textbox.html = true;
			text_mc.textbox.htmlText = this.myNews;
		}
	};
}

...I get this error:

Quote

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on handler
import mx.transitions.Tween;

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on handler
import mx.transitions.easing.*;

Total ActionScript Errors: 2 Reported Errors: 2

;)

#6 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 04 March 2007 - 09:08 PM

oh, didnt realize you had one of those kind of buttons, sorry.

try sticking the code after the on(press){

or, make a new layer in that button, and on the first keyframe put:

import mx.transitions.Tween;
import mx.transitions.easing.*;
this.onPress = function(){
_parent.redline.number = 200
;
	loadText = new LoadVars();
	loadText.load("TEXT1.txt");
	loadText.onLoad = function(success) {
		if (success) {
			// trace(success);
			_parent.text_mc.textbox.html = true;
		   _parent. text_mc.textbox.htmlText = this.myNews;

// put the tween code in here.
		}
	};
}

See if either of those work. You may need to change the _parent. Im not sure of your timeline or of the scope of your swf, so I just took a guess.

#7 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 05 March 2007 - 04:44 AM

YES!!!! You're a legend!!! The first one worked, so I didn't even have to try the second - thank you!!!

:unsure::):D

#8 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 05 March 2007 - 05:44 AM

View Postboogooloo1, on Mar 5 2007, 09:29 AM, said:

I probably should have mentioned that I'm also running funkysoul's mp3 player in this fla :unsure:
We gotta make a whole new forum devoted to helping people with this tutorial! :D

Anyway, glad Pax helped you get it working ;)

#9 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 05 March 2007 - 06:19 AM

Actually, I've got another weird thing happening - for some reason, if I change the font of the above text box, it stops working! Any reason it would only like Verdana...? :unsure:

I've tried re-embedding, in case that was the problem, but to no avail.

Any ideas? :D

@Ben: You're completely right, but of course this one didn't really have anything to do with funky's player ;)

Edited by boogooloo1, 05 March 2007 - 06:20 AM.


#10 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 05 March 2007 - 06:24 AM

Never mind - I had another text box sitting underneath accidentally :unsure:

All good now :D

#11 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 05 March 2007 - 09:46 AM

Lol, glad you got it working mate. And good debugging on your text issue :)

I should go write a debugging tutorial....

#12 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 05 March 2007 - 09:35 PM

Yep, all sorted - cheers :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users