A dynamic text field has a "scroll" property, which basically is a number telling it how many lines of text to render above the top of the frame (causing the contents to scroll). So, to set the field's scroll property to 2 will make the third line of text render at the top of the field (or close to that... I can't remember if the top-line index is 1 or 0). Anyway, to scroll a text field you'll just increase and decrease the field's scroll property, which (as you saw in your example) is easiest done with the increment and decrement operators.
increment: x++; (double plus sign. equates to: x = x+1)
decrement: x--; (double minus sign. equates to: x = x-1)
so, to adjust your text field scroll, simply do this with two buttons:
mytext_txt.text = "blah blah blah";
up_mc.onPress = function()
{
mytext_txt.scroll--;
}
down_mc.onPress = function()
{
mytext_txt.scroll++;
}
And that's it.
fatbuoy1- 12-11-2007
Thanks very much, thats a LOT simpler :D one thing though... is there a simple way to make it scroll continuously until I release the mouse button? Or do i have to create a controller mc or something that will play the scroll function on the parent clip until i release?
Also, I've been trying to use my contact form, but when I hit send nothing happens (http://www.pigstylearts.co.uk/vernacular_web2.html)
Heres the script from the form's parent timeline
stop();
//send email form
send_btn.onPress = function() {
var com:LoadVars = new LoadVars();
com.email = email_txt.text;
com.subject = subject_txt.text;
com.body = body_txt.text;
com.onLoad = function() {
gotoAndStop(2);
};
com.sendAndLoad("php/email.php");
};
//Clear Form
clear_btn.onRelease = function() {
subject_txt.text="";
body_txt.text="";
email_txt.text="";
}
and heres the php, which is pretty much what you gave me
<?php
$sendTo = "fatbuoy1@hotmail.com";
$subject = "Flash site message";
$headers = "From: " . $_POST["subject"] . "<" . $_POST["email"] .">rn";
$headers .= "Reply-To: " . $_POST["email"] . "rn";
$headers .= "Return-path: " . $_POST["email"];
$message = $_POST["subject"] ."rn". $_POST["body"];
mail($sendTo, $subject, $message, $headers);
?>
Im sure you're sick of looking at code, but im hoping something will be sticking out like a sore thumb to your trained eye :D One thing I noticed is that I can give the input boxes a variable name as well as an instance name.. should I just be doing that instead of the whole com.email = email_txt.text ...?
By the way Greg, I really can't thank you enough for all this help. I know its prett basic stuff i'm doing here, but until a week or so ago code was a closed book to me, I just couldnt comprehend it and figured I never would.. so thanks! :D
fatbuoy1- 12-11-2007
Quick update, I got the contact form working, not really sure how but its working fine for now! Thanks again :D I also changed my dynamic text field thing so it that it imports the text from an external file, should allow me to keep the text for all the sections in a single .txt file and edit them easier.. At least that's the plan.
Still trying to figure out how to make the textbox scroll continuously rather than having to keep clicking... but that will wait till tomorrow! Im away to bed :D
Thanks again
bigmac- 12-12-2007
Okay, going over points addressed... First, the email form:
I'd still suggest that you put the send email script into its own function on the parent timeline and then call that function from the button. This is an extremely good habit to get into... Buttons really shouldn't do any "thinking" in your program. A button exists to allow the user to send a message to the program. Script to that notion. This idea explodes in importance as you get deeper into OOP (object oriented programming).
As for why your email didn't work at first, I have a key point that I always look at first: did the Flash movie manage to hit the PHP script? If you're on Mac, run look at the site in Safari and open the browser's activity window. It's a great tool for reviewing what server assets are being requested and whether or not they are found. Keep in mind that a SWF's server location at run-time is that of the page that it is embedded within. That's to say if you have the following site structure:
root/ index.html
root/flash/myswf.swf
root/scripts/email.php
Assuming that index.html embeds the SWF in the flash directory, you'd use the relative path of "scripts/email.php" to hit the email script since the reference needs to be relative to the html file. Also, PHP doesn't work locally on your machine, it has to be run from a PHP enabled server that is accessed through an HTTP request. So, keep those points in mind.
I'll write a separate post about making the arrows scroll continuously.
fatbuoy1- 12-12-2007
Thanks Greg. I actually found a web tutorial for the contact form and just recreated it, and it worked. Im now going to compare the two codes and see where the previous one wasn't working... I probably just did something stupid!
bigmac- 12-12-2007
Okay, active scrolling... You've got to get into using intervals. Intervals rule, although you've got to be extremely careful with them because they can royally F*-up your program. I'll give a full explanation here since it's important to understand them before using them (and because they're poorly documented within Flash).
An interval is a repeating timer... in a nutshell, it calls a function every X seconds. You use setInterval() to start calling a function every X seconds, then clearInterval() to stop the cycle.
Now, here's the catch... intervals are quirky, which makes them tricky to use. One thing is scope (remember what that is?). An interval exists within the global space of the movie, so calling functions within the scope of a specific object is a little weird. I generally use an undocumented implementation of "setInterval()" which works quire reliably, though Flash help doesn't tell you that it works. Also, intervals are tracked by a numeric ID rather than an object reference. That means that they can't be overwritten... let me explain:
You'd think that it would work like this...
// create interval
var int = setInterval(abc);
// replace interval
int = setInterval(xyz);
In that example, you'd think that the second interval definition would replace the first so that the first would stop running and the second would run in its place. But NO. The "int" var that we created there wasn't the interval its self. It was a *reference to* the interval. When we created the second interval, the first kept right on running (calling it's function that we no longer want to be called), while the second one activated and took over it's reference. And the worst part is, since we overwrote the reference to the first interval, we have no way to go back and clear it. So, we get stuck with some outlived function calling repeatedly, consuming memory, and producing results that we no longer want. Get a few out-lived intervals running unwanted operations and you've got a downright mess within your app.
SO, the lesson here: we need to be VERY precise when working with intervals. This is where "design patters" come in. We'll need to build a design pattern that streamlines events through a standard routine that doesn't have any holes in it to let some outlived gremlin slip through. Ever heard of the term "memory leak"? This is the idea. You need to keep your app tight as a drum or else stuff slips through the cracks and compounds in negative results over time.
bigmac- 12-12-2007
Arg... seems like I'm writing tons of explanation. Hope that isn't overwhelming; you just can't learn some of this stuff without a basic understand of why a design pattern is needed. Anyway, without further ado; while I haven't -*test*-('")ed this script, this should be about what you need.
// a container for the active interval reference
var intervalId:Number;
// our text field
var myText_txt:TextField;
function setTextScroll(dir:Number)
{
if (!isNaN(intervalId))
{
// if any interval should still exist, clear it!!
clearInterval(intervalId);
}
// set new interval. Third param is interval time... 1000 = 1 second.
intervalId = setInterval(this, "scrollText", 300, dir);
// scroll once immediately in response to button click
scrollText(dir);
}
function clearTextScroll()
{
// clear active interval and reset reference to null
clearInterval(intervalId);
intervalId = null;
}
function scrollText(dir:Number)
{
// adjust text field scroll (appends direction of 1 / -1)
myText_txt.scroll += dir;
}
up_mc.onPress = function()
{
setTextScroll(-1);
}
up_mc.onRelease = up_mc.onReleaseOutside = function()
{
clearTextScroll();
}
down_mc.onPress = function()
{
setTextScroll(1);
}
down_mc.onRelease = down_mc.onReleaseOutside = function()
{
clearTextScroll();
}
Key thing to notice here is that we are only using one variable for all interval definitions. Also, before we set the interval we're checking to see if it currently is in use (ie: if it's a valid numeric ID). Theoretically, all intervals will be cleared when the buttons are released, however we're keeping that logic in place as a fail safe to make sure that one interval value never lets an interval slip past our radar.
Also note, the buttons have an onRelease AND onReleaseOutside event handler. This is crucial. onReleaseOutside is an event that a lot of noob flash developers aren't aware of and don't account for. Look it up in Flash help for what it is and why it's important.
fatbuoy1- 12-12-2007
Thanks Greg, thats just what I needed... you would think thered be a standard flash function for doing something like that wouldn't you? Im using onRollOver and onRollOut to control the buttons, but I think I can see why onReleaseOutside might be important... if you clicked on the button but released the mouse outside its hit area would it not register, causing the text to keep scrolling?
I changed the speed to 41 to make it smooth on 24fps (24x41 = roughly 1000 = 1sec).
I can see how that interval thing would be useful in saving timeline space... but i'll have to get more practice at using it properly before I try anything.
The current draft of the site is at http://www.pigstylearts.co.uk/vernacular-web2.html if you're interested
bigmac- 12-13-2007
you would think there'd be a standard flash function for doing something like that wouldn't you?
setInterval() IS the standard Flash function that rocks our world! :) Don't get me wrong, I wasn't downplaying its usefulness when I was saying that it's finicky. It makes sense and works reliably, it's just got an abnormally high learning curve on how to implement it accurately.
I changed the speed to 41 to make it smooth on 24fps (24x41 = roughly 1000 = 1sec).
Hang on there, professor... that doesn't hash. You're confusing setInterval() with onEnterFrame. onEnterFrame is tied to the frame rate of the movie, setInterval is NOT. setInterval is clock-based rather than frame based... hence the reason we're using it instead of onEnterFrame. So, the time variable that you specify for setInterval is a number representing milliseconds... 1000 = 1 second. In my example I had set the interval to 300; which is 0.3 seconds. You say that you set the interval to 41? Well, that means it will fire every 0.041 seconds. That's a little fast to scroll text!
The current draft of the site is at http://www.pigstylearts.co.uk/vernacular-web2.html if you're interested
Cool, I'll check it out!
bigmac- 12-13-2007
Cool site, it's looking good! Very nice for a first Flash effort!
fatbuoy1- 12-13-2007
Thanks very much :D its still got a lot of work to be done to it. Thanks to you I think i've got most of the coding side of things covered, i'm now going to concentrate on the animation side of things, trying to bring each area to life a bit more. The design concept is that Vernacular Language (accents, slang, etc.) is as much a part of our culture and society as architecture, literature, sports etc. So as the figure walks through the site there will be different local landmarks visible behind the wall (like the silhouette of the Albert Clock in the project brief section). Im also intending to bring sound into it by playing snippets of conversation as you walk past other people.
Id be interested to know how you found the design of the interface in general? Im trying to be a bit more imaginative, but at the end of the day it needs to be easy and intuitive to navigate the website and get the information.. no point in having bells and whistles if they make it harder to get my point across, and/or frustrate users.
bigmac- 12-13-2007
Id be interested to know how you found the design of the interface in general?
I like it. It reminds me A LOT of my early flash work which I had a ton of fun doing. School work lets you agonize over weird ways of doing stuff that is atypical and creative. What happened? Guess it's because what people ultimately want to pay for is "the formula". No offense intended in this statement, but the site's nostalgia made me miss college given that its very much a "college site". There's a lot of creativity there for the sake of being creative, which is a fantastic approach... but is (sadly) limited to the blissful years of virgin creativity that we get in college. The slow moving, concept-based animations and transitions will evolve to become fast-moving and message based if you keep going in the world of interactive marketing.
Sadly, marketers don't pay for concept... or at least, the marketers that you'll be working with in your early career. If after a few years of work experience you hire on with a marketing giant like RG/A or someone, THEN concept comes back. But then, those agencies are working with MASSIVE accounts like Coke, Nike and Target who don't care about message since they can encompass it all in a crappy little mark (ie: Nike Swoosh?). For clients that big, they're all about concept to just get people talking since their respective messages are already known as well as the alphabet. However, fresh out of college in your first job you probably won't be working on accounts like those... which means that you've got to make a Flash site for Mom & Pop's Sandwich Shop who don't care a darn thing about concept so long as their logo and address takes up half the screen.
I hope that wasn't too bleak a portrayal of what the world of interactive marketing is like... it's not so bad, really. But I do miss the old college days and designs.
fatbuoy1- 12-13-2007
Yeah I dont have any illusions about the fact that in the real world I dont get a couple of months to come up with a design that comes with a 1000-word concept statement!
I don't like just being conceptual for the sake of it, but I guess I'm making the most of exploring and experimenting different ways of doing things and designing experiences... and hoping that some of that will filter through and make my professional work a lot better.
What really interests me about design is that you're creating an experience for someone, whether its in a booklet, poster, cd, website, etc... and in terms of interactive content I think games are great examples of how to take complicated processes and content and present them with a simple and interesting interface.
You'll probably laugh at my inexperienced naiivity but I think what will keep things interesting when I do hit the real world is providing people with 'the formula'... while still maintaining a certain level of originality and even playfulness with the work.
bigmac- 12-14-2007
You'll probably laugh at my inexperienced naiivity but I think what will keep things interesting when I do hit the real world is providing people with 'the formula'... while still maintaining a certain level of originality and even playfulness with the work.
For one thing, no... I'll never laugh at ya :wink: Believe me, I've been there and done that and want to keep doing that along with you. If the design world ran like a collegiate environment, we'd have a lot wider range of work and a lot more ideas floating around. Unfortunately, you pay to go to college, it doesn't pay you. However, that's no reason to give up on idealism and hold out for that one great project where the client just says "I trust you, GO.", and you get the chance to really flex your wings a do something cool. Those are the times that make all the stupid selling out worth it.
Either way, I think you've got some great talent and an equal amount of ambition... which is a winning formula. I look forward to seeing what you'll continue to do with it!
fatbuoy1- 01-08-2008
Hi Greg, im back at this thing again (had to focus on other projects for a while there). If you have time could you take a quick look at some hashed-up code for me?
Im wanting the text boxes to appear when the user reaches each section, so iv used the following code, which seems to do the trick:
function show_text()
{
main.title_brief.brief_text.gotoAndPlay(2);
}
Then, I wanted to make it wait a wee while before it did this, so I used setInterval()
function text_appear()
{
if (!isNaN(intervalId)) {
// if any interval should still exist, clear it!!
clearInterval(intervalId);
}
// set new interval. 1000 = 1 second.
intervalId = setInterval(this, "show_text", 300);
}
This does work, but it doesnt stop, it just keeps repeating the animation. So I want to do a check to see if the loading animation has already played (i.e. reached frame 5 of the brief_text movie). This would be useful too for if the user has already been through to a section and is revisiting it, the loading animation wont load again. I thought i'd do this by just checking if the brief_text animation was at 5, and if it wasn't I would call the text_appear() function. So I thought this would work...
if (_root.main.title_brief.brief_text._currentframe != 5) {
text_appear()
}
...but it doesnt :P
Heres the whole code:
stop();
var intervalId:Number;
if (_root.main.title_brief.brief_text._currentframe != 5) {
text_appear()
}
function text_appear() {
if (!isNaN(intervalId)) {
// if any interval should still exist, clear it!!
clearInterval(intervalId);
}
// set new interval. 1000 = 1 second.
intervalId = setInterval(this, "show_text", 300);
}
function show_text() {
main.title_brief.brief_text.gotoAndPlay(2);
}
Would really appreciate any help, IF you have time :D
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.