View Full Version : Randomizing dynamically loaded text files (on reload)?
The Red Fall
June 3rd, 2004, 12:10 AM
Hello. I am interested in designing a web-site with the primary purpose of displaying various poems and songs I've written over the years. The premise is simple: I need some actionscript which will detect the number and names of text files in a certain directory, and randomly pick one of them, then load it into a text field and format it with CSS. The user should simply have to reload their browser to get another randomly loaded poem. Can someone help me with that part? I've only taken one Flash class (very light on AS) and not at all knowledgeable on making 'universal AS' and usually hard-code everything. My apologies if something similar has been asked before.. Just point me to a thread and I'll go!
Cheers,
The Red Fall.
kode
June 3rd, 2004, 12:55 AM
You'll need a server side-scripting language (such as PHP, ASP, etc.) to get the contents of the directory. Flash can't do it on its own.
Do a search in the Server-Side (http://www.kirupaforum.com/forums/forumdisplay.php?f=11) forum, you should find some useful threads. :)
The Red Fall
June 3rd, 2004, 01:03 AM
You'll need a server side-scripting language (such as PHP, ASP, etc.) to get the contents of the directory. Flash can't do it on its own.
Do a search in the Server-Side (http://www.kirupaforum.com/forums/forumdisplay.php?f=11) forum, you should find some useful threads. :)
Wow, that's interesting. I thought I saw some AS before which did something similar, or maybe it was dealing with randomizing internal stuff rather than txt files. I believe Homestarrunner.com uses Javascript to pick a random number and then load one of the menus from the result. Say if I had a set number of txt files with identical names with trailing numerals.. Could I just have Flash generate a random number, round to whole, and then pick one from that?
Eep, server side scripting has always sounded scary to me :d:
Thanks for the help, though.
The Red Fall.
kode
June 3rd, 2004, 01:14 AM
Yeah, that would be a good option if you don't want to use a server-side script (or if your server doesn't support any language).
You could use another file to define the total number of text files in the directory, load it into Flash and then generate the random number to load the text file. Of course, you'd have to update the total number of text files everytime you upload a new one. ;)
waztone
June 3rd, 2004, 03:13 AM
Or you could use XML, that way you don't have to use server-side scripting.
I'm not totally sure on how to do it but your AS would have to generate a random number everytime the page loads. This number will pick a node in an XML file where the URL of a HTML file is written and display it in your textField.
my guess of the XML file:
<?xml version="1.0"?>
<poems>
<poem nr="1">poems/poem1.html</poem>
<poem nr="2">poems/poem2.html</poem>
</poems>
or something like this. There's probably someone out there that can help you with this.
Here's something of a tutorial that I think could help you on your way.
nwebb tutorial (http://www.nwebb.co.uk/nw_htmlsite/index.php?page=browse_tutorial&tutorial=xmlhtmlcss1&part=1)
The Red Fall
June 3rd, 2004, 12:31 PM
Or you could use XML, that way you don't have to use server-side scripting.
I'm not totally sure on how to do it but your AS would have to generate a random number everytime the page loads. This number will pick a node in an XML file where the URL of a HTML file is written and display it in your textField.
my guess of the XML file:
<?xml version="1.0"?>
<poems>
<poem nr="1">poems/poem1.html</poem>
<poem nr="2">poems/poem2.html</poem>
</poems>
Thanks guys. The problem with this particular solution is I don't wish them to be separate HTML files (I don't want people to have the option to link or go to a specific poem.. so they'd have to read whatever I give 'em :P) and want the changes to happen within Flash; for each reload I want it to load a random text file into a dynamic text box on the stage. I guess I'll see what all that server-side scripting is about, if that can help (and more importantly, if someone can help me).
Cheers,
The Red Fall.
The Red Fall
June 3rd, 2004, 11:52 PM
Okay. How about this: I transcribe a set number of poems into text files, each named in succession. I then get Flash to find a random number between 1 and however many txt files I have. Then I load the text file based on the result. If and when more files are transcribed, I'd just change the range of randomized numbers. Can someone help me with that? I believe we did something similar in my VisualBasic class back in the day, but this is Flash, and I don't know this stuff in Flash ;) Thanks for the help.
The Red Fall.
kode
June 4th, 2004, 12:45 AM
Okay. How about this: I transcribe a set number of poems into text files, each named in succession. I then get Flash to find a random number between 1 and however many txt files I have. Then I load the text file based on the result. If and when more files are transcribed, I'd just change the range of randomized numbers. Can someone help me with that? I believe we did something similar in my VisualBasic class back in the day, but this is Flash, and I don't know this stuff in Flash ;) Thanks for the help.
The Red Fall.
...Isn't that what I suggested? :P
The Red Fall
June 4th, 2004, 01:22 AM
Thanks, Kode. Hopefully, this will work fine for me :) Now I have to decide whether it's too much of a hassle to force viewers to download a non-standard font (handwritten look). Too bad dynamic text fields can't embed font outlines like static ones!
kode
June 4th, 2004, 01:37 AM
You sure can embed the font outlines! ;)
Create the text field using the Text tool, open the Properties panel (with the text field selected), click on the Characters button, select All Characters (or any other option) and click Done. You could also import the font into the Library, but it's much easier that way.
The Red Fall
June 4th, 2004, 09:00 AM
You sure can embed the font outlines! ;)
Create the text field using the Text tool, open the Properties panel (with the text field selected), click on the Characters button, select All Characters (or any other option) and click Done. You could also import the font into the Library, but it's much easier that way.
Hmm.. It appears I had things switched around in my head! It's static text fields which don't allow for font outlines! I do remember that I couldn't get a layer mask to work with dynamically loaded text, though. Maybe with scriptable masks, but I've never used those before, either! Thanks, there's hope yet for this site :ne:
The Red Fall.
kode
June 4th, 2004, 09:47 AM
No problem. :)
And just in case you're interested, check out these links:
http://www.macromedia.com/support/flash/ts/documents/maskprintembed.htm
http://www.macromedia.com/support/flash/ts/documents/mask_device_fonts.htm
The Red Fall
June 4th, 2004, 01:10 PM
Hmm.. Is there any way to get the text to fade in, though? I put it in a movieclip and then realized it was still a dynamic text field inside the mc. I could then convert the textfield to a graphic, but how'd I load it into it? If it weren't for that, it'd be great.
The Red Fall.
kode
June 4th, 2004, 03:11 PM
...There you go. :P
The Red Fall
June 4th, 2004, 03:54 PM
Thanks so much! You rock! I need the motivation to learn as much Flash as you know :-P
kode
June 4th, 2004, 05:15 PM
You're welcome. :)
And I really don't know that much... I stole senocular's brain. But don't tell anyone! ;)
The Red Fall
June 7th, 2004, 03:59 PM
Hey Kode. Can you help me again? Please check your PM inbox, if you haven't already :)
The Red Fall.
kode
June 7th, 2004, 04:16 PM
No, I haven't. I'll do it now... :P
The Red Fall
June 7th, 2004, 08:05 PM
Eep! Do you have any idea why it would be resizing my text when it's uploaded? After I publish it and view it in my browser, the text looks fine, but after I upload the same files, the text is squeezed together (the line spacing is set to -22; the default of 0 made the text look way too spaced out, so I found this to work well while viewing in Flash). Is there some publish setting I'm missing, or is it possible my host (Comcast.net) could somehow be changing the formatting, which I doubt? Darn, and I thought I was all ready to get this thing... You can try going to the URL I gave you to see what it looks like for you. For me, each line is crowding the previous, making it very hard to read. More problems, gah!
EDIT: Nevermind, Kode. I just decreased the line spacing to -12, and this translated to a good spacing online. I do wonder why it looked quite different from preview on my PC and preview on web server, though :confused:.
If you wish to help me with some non-Flash stuff, I can't seem to get this statcounter.com counter to work. I set Window Mode to Transparent Windowless, which supposedly allows for HTML above or below the SWF, and pasted in the generated code for the counter into the HTML file created by Flash, but it doesn't show up when I go to the site. I'll try a few things, but if you know anything about this, I'd appreciate it muchly.
EDIT2: I'll also check if Comcast.net provides Javascript support, as that's what this code is in.
The Red Fall.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.