Ultrashock Forums > Archived Forums > other (Creative Software)
Formatting a string?

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Formatting a string?
Old 2003-07-30

Hi all -

I have a text cast member that will hold a string created from a database query. Problem is, the text is variable and may contain CRLFs, and I need to be able to change the font face and size.

This all started out simply and innocently enough (don't they all?) using 3 separate text members, but I've since had to go with this new approach because the text members sit on top of each other vertically, and the text of the first member was wrapping and overlaying on the text of the second member.

Is there a way to format the string on the fly?
I suppose I could set the locV of the other text members based on the height of the one above it, but I'd like to avoid that if possible. Is there a better way that someone can think of?

Thanks,

-- phil --
postbit arrow 17 comments | 269 views postbit arrow Reply: with Quote   
Registered User
philroy is offline
seperator
Posts: 10
2001-12-19
seperator

Ultrashock Member Comments:
lepeep lepeep is offline 2003-07-31 #2 Old  
why not use fields to feed in the data, and make the fields scrollable ?

you could then set up how they look, and it'd never change, no matter what gets fed into them...

(Or does yuor text have to look good ?..anti Alias n all that jazz).

perhaps you could think about fixing the size of the text member, and using a cusom scroller...

seems like your text is pretty dynamic (short - long stings), why bother busting your balls formatting something to fit a text mem, when you'll never account for every bit of text to be fed in there...

not really what you asked, but , an alternative thought...HTH
peep
Reply With Quote  
philroy philroy is offline 2003-07-31 #3 Old  
peep -

Thanks for the input. I probably should have provided a few more details, though.

This project is for a 'screen save' type application that will run on a large plasma monitor in the lobby of an office suite that welcomes the visiting guests for the day. As such, I can't use fields, because the text must be anti-aliased (i.e, it must 'look good'). I'm also duplicating the text member as a separate sprite to achieve a drop-shadow effect. And since this application has no user interaction, there can't be any scrolling. I must display it all on the screen so that the visitors can read it and get that 'warm, fuzzy feeling' that we know they are coming and that we welcome them to our premises. Ugh.

Anyway, you're correct in your assumption that the text is dynamic -- one visitor record may have a short name, with a city/state location beneath his name, and a meeting location for the day, all of which are different font sizes, weights, and face variations on the same base font. Another record may have a long name with several titles following (e.g., PhD, MD, etc.), no location, and a meeting location. A third record may show a group name with a small list of memebers of the group following with no meeting location.

Each of these situations must be formatted differently, and currently the application has no way of 'knowing' what type of record the visitor is since I'm reusing a general script member to load the list of visitors using getNetText.

So, is there any way to do this?

Thanks,

-- phil --
Reply With Quote  
lepeep lepeep is offline 2003-07-31 #4 Old  
Last edited by lepeep : 2003-07-31 at 07:47.
why not use imaging lingo ?

don't worry about formatting the sizes of text, just worry about the line returns , then , take an image of the text member (you'd have to convert it to a bitmap first) , then scale the bitmap WITH imaging lingo (not with physical width / height lingo , as this would make the text go jerky...

any help ?PS, how is the string being fed into director ? what does the queery look like ?

PS, this is the code I treidn in the message window, seems to work OK...
(bearing in mind I used the development "convert to bitmap" for a test...)

x = new(#bitmap)
x.name = "holder"
x.image = image(member(1).width, member(1).height, 16)

feed = member("formatted_text").image


hold = member("holder").image

hold.copyPixels(feed, hold.rect, feed.rect)
Reply With Quote  
lepeep lepeep is offline 2003-07-31 #5 Old  
****e...
I am looking for a way of converting a text member to a bitmap on the fly...
I know you can click the button "convert to bitmap"...but that's not much help when a projector is running...

i also tried member("text1").converttobitmap() but that dunt work..

I found a nice article on the matrix animation in director...he has pre rendered a whole alphabet, and copied letters out using copyPixel...
(this sounds far too long winded)...

anyway, have a read, see if it helps...
I'll keep thinking , but knowing how the string is fed in would help too...

peep

http://director-online.com/buildArticle.php?id=1117
Reply With Quote  
philroy philroy is offline 2003-07-31 #6 Old  
peep -

Thanks again for the input. I haven't used imaging Lingo, and I'm not sure that this will meet my need. But I'll look into it as a possibility.

To answer your questions, the text is being generated from a PHP script that runs a mySQL database query. The script outputs a block of text that is actually a Lingo script that I get using getNetText to feed it into a script cast member. The scripts is simply a series of lists that are used to populate the text members by looping over the lists.

Sound convoluted enough?

-- phil --
Reply With Quote  
lepeep lepeep is offline 2003-07-31 #7 Old  
if you can utilise a getnettext and PHP, I am sure imaging lingo will be a breeze...
to simplify the "getting a letter with imaging lingo", all you'd need are all the characters as single bitmaps (pretty tiny files sizes)...

apparently setting up an imaging lingo "text box" is actually quicker than displaying real text (I read somewhere...could be imaging lingo propoganda !)...

I'll try and make something that you might be able to pick appart...

peep (my names phil too !)...he he
Reply With Quote  
toxi toxi is offline 2003-07-31 #8 Old  
hi, sorry i'm very busy at the moment with other (non-director related) projects.... but you can get the image of a text member like this: myTextImage=member("mytext").image. however the actual image data (letter shapes) are only stored in the image objects alpha channel. you can extract this as 8bit greyscale image like this: myTextAlpha=myTextImage.extractAlpha()
Reply With Quote  
philroy philroy is offline 2003-07-31 #9 Old  
All -

I found the answer to what I was trying to do. I had actually seen it yesterday while looking through the Director documentation, but for some reason it didn't click. Guess that's what I get for skimming and not really reading, huh?!?

I can set the font, fontSize, and fontStyle of the member of a sprite at beginSprite by accessing the line[] and char[]. And since I'm simply creating another sprite based on that same member for the drop shadow, it already has the font properties set.

Viola! Simple one I saw it.

Thanks for the help,

-- phil --
Reply With Quote  
philroy philroy is offline 2003-07-31 #10 Old  
OK, maybe not so simple ...

Seems now that myText.line.count does not return the correct number of lines in the myText text member at run-time. Anyone know why? It works design time in the message window. I'm trying to loop through the lines and set font properties based on a property list that I created to control each line.

Anyone have any idea?

Thanks,

-- phil --
Reply With Quote  
lepeep lepeep is offline 2003-07-31 #11 Old  
hey , toxi , cheers for that tip bit...how do you know all these undocumented bits n bobs ?

Phil...can you send me an actual string of what is being fed to the handler ?
I'll see what I can do with it.

peep

lepeep@dubterror.com
Reply With Quote  
philroy philroy is offline 2003-07-31 #12 Old  
peep -

I can't send you the actual string right now because I'm at home and the app is at work, and I'll be away from my computer until Tuesday.

But basically, the lists that get made with the PHP script look like this:

list1 = ["name1", "name2", "name3"]
list2 = ["location1", "location2", "location3"]
list3 = ["room1", "room2", "room3"]

Currently the app uses 3 separate text members, say text1, text2, text3, to display the text. Each time I enter the frame where the name gets displayed, I grab the text from the appropriate list to put into the text members.

What I'm trying to do now is rather than putting the text into three different members, I put it into one text member, say myText, like so:

member("myText") = list1[i] & RETURN & list2[i] & RETURN & list3[i]

where i is incremented each time I exit the frame up to the number of items in the list. Then i is reset back to 1, and I start over. (OK, not necessarily what I would have done, but I inherited this app from someone else and didn't want to build it from the ground up!)

Anyway, at design time, Lingo says there are three lines in the member. But at run-time, it thinks there is only one. It's almost as if Lingo loses track of the RETURNs (I've also tried doing a numToChar() for the ASCII value of a CRLF -- don't remember off the top of my head what that is -- but that doesn't work either). Or maybe it's because I'm attempting to change the font properties for portions of the member. I think I recall reading a thread on lingo-l about line.count not working when there are multiple fonts being used or something like that.

One other odd thing about the app is that these particular text members span a couple of frames in order to do some cheesy frame transitions (again, not what I'd do). Is there any chance that the updating of the stage by the transition is goofing things up? I haven't tried testing this in a different .dir file without all the different things going on. Maybe that's the next thing I should do.

At any rate, I'd love to know why this is happening. I'd like to be able to count the number of lines in the text member and loop over them, setting the font props from a global font props list. But if Lingo only sees one line of text, then I only get one shot at setting the font.

Thanks again for all the help. This is a weird one.

-- phil --
Reply With Quote  
philroy philroy is offline 2003-07-31 #13 Old  
peep -

One last thing I forgot. The part of the script that puts the pieces of the text together actually looks like this:

member("myText") = list1[i] & RETURN & \
list2[i] & RETURN & \
list3[i]

Is there any chance that the 'continued on next line' charactier is biting me? Sounds crazy, but that just popped into my head.

Thanks,

-- phil --
Reply With Quote  
lepeep lepeep is offline 2003-08-01 #14 Old  
I tried this, I think another difference is there are no spaces in the code where I have the "&" and the "RETURN"...might not matter, but this code works.

to get a "random 3 lines", just call : makeString()

Peep - sent you this in an Email too (with attachment)


global tList

on startMovie
tList = [#names:["jeff", "john", "frank", "bob", "mary", "jenny", "gabi", "phil", "steven", "shelli", "rich"],#meetingroom : ["room 1", "room 2", "room 3", "room 4"],#address : ["14 ponce street", "15 fattyarbuckle av", "12 fortification road", "6 lesbee av.", "44 burt street"]]
end

on makeString
myName = Tlist.names[random(tlist.names.count)]
myMeet = Tlist.meetingroom[random(tlist.meetingroom.count)]
myAdd = Tlist.address[random(tlist.address.count)]
return(myName&RETURN&myMeet&RETURN&myAdd)
end
Reply With Quote  
toxi toxi is offline 2003-08-01 #15 Old  
peep, this has nothing to do with being undocumented just taken the fact for granted that every visual castmember has an .image or .picture property... if you want to read about undoc'ed things though, i recommend: http://www.director3d.de/
Reply With Quote  
lepeep lepeep is offline 2003-08-01 #16 Old  
its pretty undocumented that the image of a tex member is actually in the alpha channel...no ?

you de man.

peep
Reply With Quote  
philroy philroy is offline 2003-08-04 #17 Old  
peep -

Thanks for the help! I'll try your code as soon as I get back into the office. I'm still technically on vacation today.

Thanks again,

-- phil --
Reply With Quote  
lepeep lepeep is offline 2003-08-05 #18 Old  
Toxi, I tried the image of a text member, I think why I have always thought it never worked is that I always opened the bmp in the paint window, it comes in looking like a lack rectangle !....(try dragging it onto the stage you moron...)...ahh, I see now !....they do work !...

he he..thanks for the tip.

"remember I'm a moron"...
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: