PDA

View Full Version : Just for Kicks Challenge 1


Jesse
04-11-2003, 12:57 PM
OK so this is what I'm thinking. I look at our site and notice that while the forums are active, submissions to competitions, and in fact, submissions general seem to be pretty low compared to other similar sites in the Flash field and, in fact, similar sized community sites in general. That's a bit disappointing as it leaves most of the content creation down to the regulars, but that's another story.

Since the forums are the most active area of the site, I've decided to start a bit of a thing here and see if it takes off. My idea is this: how about we run a competition, or perhaps we should just call it a challenge, for which ActionScript.org offers no prize. Further, Strok and I won't be the judges; you guys will. So basically you're just entering for kicks and to show your stuff. Now for that reason, the task at hand can't be anything too complicated, so as to not take too much time out of your day. At the same time the script generated should be useful in some practical sense.

So here's my idea for the first Just for Kicks Challenge:
In 25 lines or less (stolen from Bit-101's competition) create something which enhances the coolness, usability, appearance, intuitiveness of a Flash MX TextField. Comments don't count as lines. The line limit is for construction of your feature only: code which demonstrates it in action doesn't count. Standard "what is a line" rules apply. Entries should be code only I think, but I guess we could allow some visual elements too. Fancy animation won't win it for you though.

Submit your code via this thread. Entries will close in 14 days from today. If this one takes off we can run them more frequently. If people think this particular challenge is stupid but the idea is good, say so and suggest some other idea for the challenge; that's literally just what came to mind while I was writing this thread.

If this one takes off, then we can run these heaps more often. I'll enter tomorrow or later in the week when I have a chance to code something. Since I'm not going to judge the winner I think I should be allowed to enter this one :)

Jesse
04-11-2003, 01:48 PM
I hate to be the one to respond to my own thread, but I got carried away with this idea and thought of an idea for my entry. So here it is:
In IE (4+...?)when you're filling in forms online, if the field has the same name as a field you've filled in previously, and autocomplete is enabled, it gives you a list of values you've previously used. This system sort of replicates that in a very basic way. Really what it does is store values entered into fields based on the name of the field, in a SharedObject, then, on request, it populates the field with a value from the SharedObject should one exist. At present the function must be invoked manually but you could set it up such that as soon as the field gets the cursor focus it checks the SO for the last value and populates it. The code is as follows:
TextField.prototype.recordPastValues = function() {
if (!_global.fieldList) {
_global.fieldList = new Array();
}
_global.fieldList.push(this);
this.onKillFocus = function(newFocus) {
trace("Recording value: "+this.text);
_global.pastValues_so.data[this._name] = this.text;
_global.pastValues_so.flush();
};
};
TextField.prototype.populateFromPastValues = function() {
_global.pastValues_so = SharedObject.getLocal("pastValues");
if (_global.pastValues_so.data[this._name] != undefined) {
this.text = _global.pastValues_so.data[this._name];
}
};
_global.pastValues_so = SharedObject.getLocal("pastValues");
Here's some code which impliments it. Create the buttons manually as I hate coding buttons:
// Show it in action (lines below here don't count)
// Create a new input field
_root.createTextField("someField_txt", 1, 20, 20, 200, 20);
someField_txt.type = "input";
// Enter a value in the field
someField_txt.text = "cars";
// Register values in SO (assumes enabled, bad bad boy)
someField_txt.recordPastValues();
// Setup these two buttons in your FLA
// Chage the text field value
but1_btn.onRelease = function() {
someField_txt.text = "dog";
};
// Retrieve last value from SO
but2_btn.onRelease = function() {
someField_txt.populateFromPastValues();
};

linckx
04-11-2003, 02:20 PM
Hi Jesse,

I've never even used textfields for anything more than to show a variable or put text in it, so don't expect any fancy coding from me.

I really like the idea though, but what I think will be 'most' attractive for new users is to be as creative as possible with 'standard coding'...

robin

simontheak
04-11-2003, 03:36 PM
Cool idea Jesse - I've seen these kind of open competitions on other forum sites and always thought that that was something that was missing from actionscript.org.

I'll have a good think about it over the weekend and if I come up with something I'll post it up.

Really hope this takes off though

Billy T
04-11-2003, 04:18 PM
here's a little one

hit the up and down arrows on your keyboard

cheers

boyzdynasty
04-11-2003, 04:27 PM
linchx...sh0w us some of that expensive talent. ;)

Jesse great idea. I can try to do some stuff for fun. Won't be the best *gauranteed--and no refunds*
O..you should have created a *.fla file for us like BillyT ;)

So...will you be making some kind of voting poll in this thread when the comp. is over?

linckx
04-11-2003, 04:34 PM
hi boyz...

the expensive part was me being your friend,
now the flash part, I'll throw it in for free, because what you can do yourself, you can do better, in other words:

If I were capable to create something with textboxes, it wouldn't be new.

But I do have an idea: A while ago there was someone here and he asked how to create 'refrigerator magnets' and someone made it for him(or her, sorry bluegel :o).

think that'd look nice :)

robin

freddycodes
04-11-2003, 06:24 PM
Question,


The whole thing including implementation should be under 25 lines, no?

Billy, yours is 27, I am sure by moving things around you could take it up under 25 though.

Jesse you are at 28 without comments.

So are we sticking to the 25 line limit?

pom
04-11-2003, 06:28 PM
I don't want to ruin the party or anything, but TextField are not very inspiring. I understand you're trying to get something usable and not just good-looking, but extending the TextField prototype isn't very sexy. Bit's contest was :)

My 2 Eurocents, thank you very much.

pom :)

freddycodes
04-11-2003, 06:32 PM
Sorry I didn't read the instruuctions and I now realize that implementation does not count in line count, however it should, its too easy the way it is now.

pom
04-11-2003, 07:40 PM
The less usable, most unuseful thing ever to see the surface of the Earth...

*drum rolls*

I give you...........

The silly TEXTFIELD INVERTER!!! thank you very much// copyright pom, just in case you want to steal this little wonder
TextField.prototype.enterInvert = function(str){
var mc = _root.createEmptyMovieClip("controller",1000001);
mc.ref = this;
var count = str.length;
controller.onEnterFrame = function(){
if (count > 0){
var a = str.slice(count-1,count);
count--;
this.ref.text = a + this.ref.text;
}
}
}
this.createTextField("myText",0,50,100,400,20);
myText.enterInvert("ilyas est vraiment trop fort");You can simply copy and paste in the Actions panel.

I'll probably upgrade it as time goes by. Probably.

freddycodes
04-11-2003, 07:58 PM
Here is my lame attempt at a 5 line work of art :rolleyes:


TextField.prototype.toggleUnderline = function() {
var newU = (myFormat.underline == true) ? false : true;
myFormat.underline = newU;
this.setTextFormat(myFormat);
}

var mc = _root.createEmptyMovieClip("holder", 0);
mc.createTextField("testText",1,0,0,1,1);
_global.myFormat = new TextFormat("Arial", 16, 0xFFFFFF, 1, 0, 0);
mc.testText.autoSize = true;
mc.testText.text = "I am some sample text";
mc.testText.setTextFormat(myFormat);
mc.onRollOver = function() { this.testText.toggleUnderline();};
mc.onRollOut = function() { this.testText.toggleUnderline();};

littleRichard
04-11-2003, 09:57 PM
it's a bit buggy but changes the font size up or down without using a TextFormat() object so that if won't mess up any size formatting that's already been applied:


TextField.prototype.grow = function()
{
var x = this._x;
var y = this._y;

var w = this._width;
var h = this._height;

this._xscale += 10;
this._yscale += 10;

this._width = w - ((this._xscale - 100) / this._xscale * w);
this._height = h - ((this._yscale - 100) / this._yscale * h);

this._x = x;
this._y = y;
};

TextField.prototype.shrink = function()
{
var x = this._x;
var y = this._y;

var w = this._width;
var h = this._height;

this._xscale -= 10;
this._yscale -= 10;

this._width = w - ((this._xscale - 100) / this._xscale * w);
this._height = h - ((this._yscale - 100) / this._yscale * h);

this._x = x;
this._y = y;
};

Jesse
04-12-2003, 04:38 AM
Hey I'm really pleased to see that people are into the idea, even if this this particular topic isn't so great. Some really groovy contributions already.

I'll upload a FLA of mine later on today.

If people answer the questions below it will help us determine what shape the next of these challenges should take:
- Should implimentation lines be included in the line count?
- What should the line limit be?
- What should the object of the next one be?

I really just chose TextFields because I was thinking about usability as someone mentioned above. It's an objective of mine to bring Flash up a bit in the eyes of managers and CEOs who currently seem to think it's just an annoying advertisement or intro tool.

Keep those contributions on this one going and in a week and a bit we'll start another based on the answers to the above questions.

pom
04-12-2003, 02:42 PM
I say we do like in Ol' Bit's contest: eye-candy in 25 lines. My 2 Eurocents once again.

Billy T
04-12-2003, 04:35 PM
nah I reckon Jesse's idea of usable stuff is better

littleRichard
04-12-2003, 05:27 PM
I like the usabilty idea but if the point is just that, to come up with truely usefull stuff then i'm not so sure i like the 25 line rule.

buggedcom
04-12-2003, 05:40 PM
this isn't mine but i would like to volunteer this i found at layer 51 created by H20 that i slightly trimmed here and there to fit the 25 lines. it's a nice effect, how usefull it could be well i don't know about that one.

original here (http://proto.layer51.com/d.aspx?f=747)

TextField.prototype.deCript = function(myMsg) {
var crpt;
var tf = this;
tf.autoSize = true;
tf.msg = myMsg;
var lung = tf.msg.length;
for (var a = 0; a < lung; a++)
crpt += String.fromCharCode(33 + Math.round(Math.random() * 90));
var id = setInterval(function () {
var trimmed;
var cripted = new String(crpt);
var newString = new String(tf.msg);
if (i <= tf.msg.length - 1) {
sliced = newString.slice(i, i + 1);
deCrip += sliced;
i++;
var trimmed1 = cripted.substr(i, lung);
for (var k = 0; k < trimmed1.length; k++)
trimmed += String.fromCharCode(33 + Math.round(Math.random() * 90));
tf.text = deCrip + trimmed;
}
if (deCrip == tf.msg)
clearInterval(id);
}, 70);
};


//implementation
this.createTextField("myTxt", 1, 0, 0, 1, 1);
message = "decripting some silly text in a textbox";
myTxt.deCript(message);

Billy T
04-13-2003, 02:34 AM
Originally posted by littleRichard
to come up with truely usefull stuff then i'm not so sure i like the 25 line rule.

yep I agree with you there.

boyzdynasty
04-13-2003, 03:24 AM
i know i shouldn't be asking questions...but i liked what BuggedCom posted.

Now...the thing is I want to use a preferred font. But I'm sure the font is not installed in everyone comp.

So how do i do this in actionscript.... the name of the font I want to use is called "Alexis"

any tips?


p.s.

I just thought it would be something cool to use as a loader instead of the usual load bar.....

farafiro
04-13-2003, 07:39 AM
so, is it just a code or may I use some components

bsaltysiak
04-13-2003, 07:40 AM
Let me know what you think of my first post. Here is the actionscript equivalent (and quick hack) of a piece I did to the SmallTalk kernel a couple years back. I'm afraid it's not very efficient but I don't have much time (or space ;)).

Basically it gives you that MS Word functionality where it replaces mistyped words automatically, while typing. Meaning if you type: 'fi' it will correct it to 'if'. I only build in: fi->if, adn->and, hte-> the. But it's supremely easy to add more.

In 23 total lines (I don't know what counts exactly):

TextField.prototype.mappingObj = {adn:'and', fi:'if', hte:'the'};
TextField.prototype.onKeyDown = function () {
if (Key.getCode() == Key.BACKSPACE) {
TextField.prototype.buildWord = TextField.prototype.buildWord.substring(0, this.buildWord.length - 1);
} else {
if (Key.getAscii() >= 32) {
var lastChar = String.fromCharCode(Key.getAscii());
if (lastChar == " ") {
TextField.prototype.lastWord = TextField.prototype.buildWord;
TextField.prototype.buildWord = "";
} else {
TextField.prototype.buildWord += lastChar
}
}
}
}
TextField.prototype.onChanged = function () {
if (this.mappingObj[TextField.prototype.lastWord] != undefined) {
this.text = this.text.substring(0,this.text.length - (1+TextField.prototype.lastWord.length)) + this.mappingObj[TextField.prototype.lastWord] + " ";
TextField.prototype.lastWord = "";
}
}
Key.addListener(TextField.prototype);


enjoy

Jesse
04-13-2003, 11:37 AM
I know eye-candy is good but I chose to go the usability route for the reason I mentioned earlier. I think we can make a more positive contribution to the use of Flash by working on usability and cool features rather than eye candy, although the candy is great too. I guess I have a bit of a bias also as I'm no mathematician and candy generally involves lots of math-based coding.

The line-count issue being a problem in terms of usability promotion is another valid point but so far I've seen some really cool additions. Customizable text sizes at the press of a button for instance. Short, sweet, easy to use and great for user interaction.

I particularly like bsaltysiak's entry.

I like the idea of a short line count because otherwise people can go overboard. My entry for instance, could be customized to remember the last 10 words entered into a field with that name and when the user starts typing it could dynamically attach a listbox with the options for them to click on to auto-fill. It would be cool but ultimately it's the core functionalities I think we should be working with. Some of this comes from a conversation I had with Dave Emberton last week about how Flash isn't as much fun any more because there are very few limits. His argument was that when the limits disappear ingenuity sometimes goes with it.

Keep those entries coming.

pom
04-13-2003, 11:54 AM
bsaltysiak >> Very cool, Mister :)

Billy T
04-13-2003, 02:11 PM
Originally posted by pom
bsaltysiak >> Very cool, Mister :)

yep that's funky

way to make an entrance bsaltysiak ;)

jubei
04-13-2003, 10:48 PM
I say stick with usability, it's an original idea. And i'd even suggest cutting the line count down - like you said Jesse, without limits it's difficult for ingenuity.

Personally, i see stuff like this and think "what's the point in entering, i wouldn't be able to come up with anything half as good as you guys"... but if there's a limited line count, i think i'll be more tempted. After all, there's only so much -anyone- can do with 25 lines.

farafiro
04-14-2003, 08:45 AM
search engin, not so cool but can be a post
//********************** Search For enging **************************
//*******************copy right: farafiro, but you can use it with some credit here
//making the text fields
//the search text field
_root.createTextField("search", 10, 10, 10, 150, 30);
search.border = true;
search.type = "input";
//the main text field "data"
_root.createTextField("data", 20, 10, 50, Stage.width-50, Stage.height-50);
data.border = true;
data.type = "input";
data.multiline = true
// The "find" button
_root.createEmptyMovieClip("find", 5);
with (find) {
moveTo(175, 10);
beginFill(0x336699);
lineTo(250, 10);
lineTo(250, 40);
lineTo(175, 40);
endFill();
}
// Finding the word script
find.onRelease = function() {
findWhat = data.text.indexOf(search.text);
if (search.text != "" && findWhat>=0) {
Selection.setFocus("_root.data");
Selection.setSelection(findWhat, findWhat+search.text.length);
} else {
trace = "That word you are searching for could not be found";
}
};

Jesse
04-14-2003, 11:05 AM
Nice one Faffy. Suggested improvement for the future: the second and later clicks on the find button should find the next occurence of a search term; at present it always finds the first match.

farafiro
04-14-2003, 11:29 AM
I know but my head is outta my body now, and it needs some thinking
maybe later but any modifications are welcomed

xxlm
04-14-2003, 11:34 AM
coming back to my place wenesday I will try to find some I have made already and post it...

Else, yeah those competition are good. good for the brain and for everybody (mean you can find lots of stuff)..
And 25 lines of REAL CODE is enought I think. Yeah it puts some difficulties and it's good for brain too
CU

CyanBlue
04-14-2003, 11:43 AM
A little bit of modification on farafiro's script...
Don't know if this goes with 25 lines or less category though... :D// ********************** Search For engine **************************
// *******************copy right: farafiro, but you can use it with some credit here
// making the text fields
// the search text field
_root.createTextField("search", 10, 10, 10, 150, 30);
search.border = true;
search.type = "input";
// the main text field "data"
_root.createTextField("data", 20, 10, 50, Stage.width - 50, Stage.height - 50);
data.border = true;
data.type = "input";
data.multiline = true;
// The "find" button
_root.createEmptyMovieClip("find", 5);
with (find)
{
moveTo(175, 10);
beginFill(0x336699);
lineTo(250, 10);
lineTo(250, 40);
lineTo(175, 40);
endFill();
}
search.onChanged = function ()
{
startPoint = 0;
}
// Finding the word script
find.onRelease = function()
{
findWhat = data.text.indexOf(search.text, startPoint);
if (search.text != "" && findWhat >= 0)
{
Selection.setFocus("_root.data");
Selection.setSelection(findWhat, findWhat + search.text.length);
startPoint = findWhat + 1;
}
else
{
trace("That word you are searching for could not be found");
}
}

farafiro
04-14-2003, 12:06 PM
nice one mate, so can we post it as one "CyanFara", lol

it's 25 lines exactly man ;)

CyanBlue
04-14-2003, 12:09 PM
Hahaha... I had to actually remove comments and brackets to see if it IS 25 line and it IS... :D

As for the credit... It was your idea and I happened to be there while you posted it... and I didn't do much on that... So, it still IS 'farafiro' code... ;)

farafiro
04-14-2003, 12:17 PM
wow, that's cool
thx, I will sell it right now :D

bit-101
04-14-2003, 01:01 PM
i demand 10% of the winnings of this competition for stealing my 25 line idea.

oh, "just for kicks?" - well, i still expect at least a half dozen kicks! :D

seriously though, a few people mentioned they don't like the 25 line thing. the reason i always liked it is that it forces you to really think about what you want to do, and what the code is doing internally, and more elegant, simple, precise ways to do the same thing. it was always more of an intellectual excersize than good programming techniques. you can learn a lot by imposing a restriction like that. but the resulting code may not be very readable or maintainable.

good to see others enjoying the idea.

pixelwit
04-14-2003, 01:42 PM
Why not make it a file size limitation?

As Bit101 mentioned the line limitation tends to lead to some rather unruly coding techniiques. If you only limit the size of the finished SWF it will allow a little more freedom in your code structure and would also enable the use of stage objects.

Freedom with limitations.

Just an idea.

-PiXELWiT
http://www.pixelwit.com

farafiro
04-14-2003, 02:00 PM
Pix, I think this would also make the same effect
less lines would make also small file size

but I think the famouse 25 line contest belongs firstly to were-here (www.were-here.com), it was very cool

pixelwit
04-14-2003, 02:46 PM
This code isn't necessarily the best example, but it'll do:var kl = {};
Key.addListener(kl);
kl.onKeyDown = function () {
var lastKey = String.fromCharCode(Key.getCode());
trace(lastKey);
if (lastKey == 'A') {
word = "Apple";
} else if (lastKey == 'B') {
word = "Book";
} else if (lastKey == 'C') {
word = "Car";
} else if (lastKey == 'D') {
word = "Dog";
} else if (lastKey == 'E') {
word = "Egg";
} else if (lastKey == 'F') {
word = "Fungus";
} else if (lastKey == "G") {
word = "Good";
}else{
word = "";
}
trace(word);
}
kl.onKeyDown = function(){
var lastKey = String.fromCharCode(Key.getCode());
word = lastKey == "A" ? "Apple" : lastKey == "B" ? "Book" : lastKey == "C" ? "Car" : LastKey == "D" ? "Dog" : lastKey == "E" ? "Egg" : lastKey == "F" ? "Fungus" : lastKey == "G" ? "Good" : "";
trace(word);
}If you look at the two onKeyDown functions you'll see that the first example is roughly 5 times larger if you use the line counting method, but if you were to judge them by file size the difference wouldn't be nearly as great.

This would allow for greater code legibility, flexibility and usability without taking away from the contest's intent of keeping things short and sweet.

-PiXELWiT
http://www.pixelwit.com

bit-101
04-14-2003, 02:50 PM
Originally posted by farafiro
Pix, I think this would also make the same effect
less lines would make also small file size

but I think the famouse 25 line contest belongs firstly to were-here (www.were-here.com), it was very cool

someone, i think senocular, originally did a 50 line contest on wh. i think it was around xmas 2001. it was great. a little later i did a 25 line contest, also on wh, and it somehow got talked up all over the net. then i continued it on my own site for a while.

farafiro
04-14-2003, 02:58 PM
ah
that I didn't know
but the first I saw there wasn't created by you, but in there
;) :D

Jesse
04-14-2003, 09:23 PM
Pix - That's why I said "Normal 'What is a line' rules apply". Those stupid ?: if else statements don't count :)

pixelwit
04-14-2003, 09:50 PM
I guess I missed the "Normal" line comment. Thought it was like Bit101's contest. Pretty sure ?:'s were allowed in there. Also saw things like a series of functions defined in arrays and all sorts of other tricks.

Are you sticking to an all code format? Can we use clips from the Library instead of drawing them with script? If so can they be any file size?

How about a character limit rather than a line limit? Somebody could probably come up with a non-whitespace character counter for a textfield. ;)

Just some thoughts.

-PiXELWiT
http://www.pixelwit.com

Jesse
04-14-2003, 10:11 PM
I dunno. Personally I see no harm in being able to attach basic elements like a button, etc, rather than draw them and eat into the line count.

As unrelaistic as a line limit seems int he real-world of Flash development, I think we should stick to allwing people some freedoms they would otherwise use. I personally never darw buttons witht he API, I attach them.

What do others say?

farafiro
04-15-2003, 06:20 AM
I say, just stick to the 25 lines code only, no attachment, nothing on the stage.
I couldn't belive the thoughts and the reading trying to get more knowledg that came up while joining Bit's contest

Krxtopher
04-16-2003, 07:13 PM
This contest is a great idea! It inspired me to become a member of this site (which I just found today).

I hope you like my entry. It enables auto-completion as you type referencing a user-defined dictionary. Exactly 25 lines!...


// INSTRUCTIONS:
// Place this code on the same frame as an input field with the
// instance name "Field_txt".

Field_txt.onSetFocus = function () {
Key.addListener(this);
}

Field_txt.onKillFocus = function () {
Key.removeListener(this);
}

Field_txt.onKeyUp = function () {

// Don't auto-complete if the text length hasn't changed (ex. arrow key pressed)
// or if DELETE or BACKSPACE were pressed.
if ( this.vLastLength == this.text.length || Key.getCode() == 46 || Key.getCode() == 8 ) {
this.vLastLength = this.text.length;
return;
}

// Record selection span and beginning of word segment.
var vSelStartIndex = Selection.getBeginIndex();
var vSelEndIndex = Selection.getEndIndex();
var vWordStartIndex = this.text.lastIndexOf(" ", vEndIndex) + 1;

// Determine word segment to check against.
var vWordRoot = this.text.substring(vWordStartIndex, vSelEndIndex);

// Search through dictionary (vDictionary_arr) for a match.
for ( var i=0; i<vDictionary_arr.length; i++ ) {
if ( vDictionary_arr[i].indexOf(vWordRoot) == 0 && vWordRoot != "" ) {
// ?? Match found! Add it to the field and select it.
this.text = this.text.slice(0, vWordStartIndex) + vDictionary_arr[i] + this.text.slice(vSelEndIndex, this.text.length);
Selection.setSelection(vSelEndIndex, vWordStartIndex + vDictionary_arr[i].length);
break;
}
}

this.vLastLength = this.text.length;

}

// Define a custom "dictionary" of auto-completion terms.
vDictionary_arr = ["cat", "catastrophy", "candle"];


- Kris

xxlm
04-16-2003, 08:30 PM
TextField.prototype.scrollTextInit = function (myText, speed) {
this.text = myText;
this.startChar = 0;
while (this.textWidth > this._width) {
this.text = this.text.substr(0 , this.text.length - 1)
}
this._scrollText = setInterval(this.scrollText, 120, myText, speed, this);
};

TextField.prototype.scrollText = function (myText, speed, TheTextfield) {
if (TheTextfield.startChar+TheTextfield.text.length >= myText.length) {
TheTextfield.rest = TheTextfield.text.length - (myText.length-TheTextfield.startChar);
TheTextfield.text = myText.substring(TheTextfield.startChar, (myText.length) )+" ... "+ myText.substring(0, TheTextfield.rest-5);
if (TheTextfield.rest == TheTextfield.text.length) {
TheTextfield.startChar = 0;
}
} else {
TheTextfield.text = myText.substring(TheTextfield.startChar, TheTextfield.startChar+TheTextfield.text.length);
}
TheTextfield.startChar += speed;
updateAfterEvent();
}

//eg:
_root.createTextField("test", 1, 0, 0, 100, 24);
test.scrollTextInit("Ok this is the text to be scroll, it's easy to use: just put the text and the speed. Hope you will like. Cu" , 2);


Ok, as the name say it, this script scroll a text like inside a banner...

hope you like ... cu :)

mpol777
04-16-2003, 10:03 PM
function BenchMark() {
this.startDate = null;
this.startTime = 0;
this.endDate = null;
this.endTime = 0;

this.start = function() {
this.startDate = new Date();
this.startTime = this.startDate.getTime();
this.endDate = null;
this.endTime = 0;
}

this.end = function() {
this.endDate = new Date();
this.endTime = this.endDate.getTime();
}

this.getSeconds = function() {
return (this.endTime - this.startTime) / 1000;
}

this.reset = function() {
this.startDate = undefined;
this.startTime = 0;
this.endDate = undefined;
this.endTime = 0;
}
}



example:

parsingBM = new BenchMark();
parsingBM.start();

// do a whole bunch of parsing or other cool stuff

parsingBM.end();
trace(parsingBM.getSeconds());

xxlm
04-16-2003, 10:18 PM
Thinking it was just for textfield... no?

Jesse
04-16-2003, 10:24 PM
Kris - Nice work. I'd fancy being able to press ENTER to accept the autocomplete, or something similar.

xxlm - Nice swing on a classic concept.

mpol777 - Although it's not for TextFields, still groovy.

mpol777
04-16-2003, 10:37 PM
Originally posted by Jesse
mpol777 - Although it's not for TextFields, still groovy.

hmmm missed that part.

you could always output the results to a text field :D

Krxtopher
04-17-2003, 03:29 AM
Jesse - maybe if you can point me to the "what counts as a line" info I can sneak in another couple lines to handle the "enter" key functionality you mentioned. Where might I find those "rules"?

- Kris

littleRichard
04-17-2003, 05:20 AM
this will return an array of scroll positions indicating the start positions of each page. you can use it to create paging navigation rather than scrolling navigation. your content dosn't have to all be at the same point size for it to work.


TextField.prototype.getPageScroll = function()
{
var local = {textLength:this.text.length, lastSelectionPoint:0, lastPageScroll:1, currPageScroll:null, lineCount:null, pageScroll:[]};

Selection.setFocus(this);
for(var c = 0; c <= local.textLength; c++)
{
Selection.setSelection(c, c);
if (this.scroll != local.lastPageScroll)
{
local.currPageScroll = this.scroll;
Selection.setSelection(local.lastSelectionPoint, local.lastSelectionPoint);

if(local.currPageScroll != this.scroll)
{
local.pageScroll.push(this.scroll);
local.lineCount = local.lastPageScroll = local.currPageScroll;
local.lastSelectionPoint = c;
}
else
{
local.lastPageScroll = this.scroll;
local.lineCount += 1;
}
}
}

if(local.lineCount == local.pageScroll[local.pageScroll.length - 1]) return local.pageScroll;

while(true)
{
this.htmlText += "<br>";
Selection.setSelection(this.text.length, this.text.length);
local.currPageScroll = this.scroll;
Selection.setSelection(local.lastSelectionPoint, local.lastSelectionPoint);

if(local.currPageScroll != this.scroll)
{
local.pageScroll.push(this.scroll);
return local.pageScroll;
}
}
};


the code is 24 lines long assuming single statement if's equal 1 line: if(condition) statement;

Rich

farafiro
04-17-2003, 06:38 AM
Krxtopher
this is vey coolmpol777:
you could always output the results to a text field heheheeeeeee
lol

pom
04-17-2003, 05:07 PM
Yep, I like it, Krxtopher :)

By the way, does anyone know how to not select everything in a textField when you press TAB? I can't get it to work :(

CyanBlue
04-18-2003, 02:52 AM
Yo... Pom... ;)

Um... What about setting the cursor point to the beginning or the last position of that text field when the TAB key has been pressed??? You can use Selection.onSetFocus and Selection.setSelection...

I think that should work... Let me know how it goes... ;)

farafiro
04-21-2003, 06:44 AM
yes, Cyan's way would work great theoritcaly but with the TAB i doubt.
you can't even use the Key.getAscii() with the TAB

red penguin
04-23-2003, 05:27 AM
Wow...This slipped right on by. Cool. I think it's a great idea.

One: It is a bit resticting but it does make us think a bit differently than usual. Many of the ideas, I believe, can be springboards for improving functionality or making it better from a programming standpoint for future use.

Two: That said, I went through the archives and discovered something that is...well...something. A friend wanted to figure out how she could, if possible, replace all occurances of any <img> tags with an <a> link from a feed she was getting from her journal.

Whoa. I took the challenge and came up with this little ditty:
String.prototype.replace=function(find,replace) {
var result = this.split(find);
return result.join(replace);
}
String.prototype.img_tag = function (find,replace,col) {
var str = this;
var newStr=str.replace(find,replace);
for (i=0; i<=newStr.length; i++) {
if (newStr.charAt(i) == replace) {
var begin = i+2;
var end = newStr.indexOf ('"', begin);
var a = newStr.substring(begin,end);
var b = a.substring(a.lastIndexOf('/')+1,a.length);
var alink = "u><b><font color=\"" + col + "\"><a href=\"" + a + "\" target=\"_blank\">" + b + "</a></font></b></u>";
newStr=newStr.replace(replace+'"'+a+'">',alink);
}
}
return newStr;
};
sans=new TextFormat("_sans",null,null,true,null,null,null,null,"left");
this.createTextField("txt_display", 51, 0, 0, 500, 20);
txt_display.html=1;
str_test = 'Here is a picture: <img src="http://www.foo.com/imgs/pic_01.jpg"> and then another: <img src="http://www.foo.com/imgs/pic_02.jpg">';
txt_display.htmlText = str_test.img_tag('img src=','~','#b22222');
txt_display.setTextFormat(sans);
So I basically set myself a marker and then find it to then replace it using a search and replace prototype (MoMad@layer51) as well.
25 lines without any comments (which help see what's going on inthere..it IS a bit convoluted)...

So a solution to a problem I once had....

Heh...the AS formatting was all screwy. Maybe all those quotes? Good ole PHP formatting worked though!

mpol777
04-23-2003, 05:01 PM
ok here's one that actually uses a text field. if you have a text field this will search the entire field and hilight any string passed into it. similar to the hilighting in vi.


// hilight text format
hilightText = new TextFormat();
hilightText.font = "Arial";
hilightText.size = 12;
hilightText.color = 0xFF0000;

// function to hilight searched text in output
function hilight(value) {
sourceClipMain.textbox.setTextFormat(outputText);
cText = sourceClipMain.textbox.text;
tArray = cText.split(value);
occurs = tArray.length-1;
if (occurs > 0) {
startIndex = 0;
endIndex = 0;
for (i=0; i<occurs; i++) {
startIndex = cText.indexOf(value,endIndex);
endIndex = startIndex+value.length;
sourceClipMain.textbox.setTextFormat(startIndex,en dIndex,hilightText);
}
} else {
debug("PATTERN NOT FOUND");
}
}

buggedcom
04-24-2003, 01:15 AM
i like that a lot, been looking for something like that, too lazy to make my own. i converted it to prototype for you


TextField.prototype.highLight = function(value, tf) {
var cText = this.text;
var tArray = cText.split(value);
var occurs = tArray.length - 1;
if (occurs > 0) {
startIndex = 0;
endIndex = 0;
for (i = 0; i < occurs; i++) {
startIndex = cText.indexOf(value, endIndex);
endIndex = startIndex + value.length;
this.setTextFormat(startIndex, endIndex, tf);
}
} else {
debug(" PATTERN NOT FOUND ");
}
};

McGiver
04-24-2003, 09:24 PM
Cool a contest! :)
oh, damn, pom copyrighted his work...um...can't steal it...um seems like i have to make an own:

onClipEvent (enterFrame) {
//Beginn Code (Z.3)
function checklength(b_text, char, keyword) {
keychar = 0;
do {
if (!((b_text.charAt(char+keychar) == keyword.charAt(keychar)))) {
return (false);
}
keychar = keychar+1;
} while ((keychar<keyword.length));
}
function search(b_text, keyword, replaceword) {
char = 0;
do {
if (!(checklength(b_text, char, keyword) == false)) {
char = char+keyword.length-1;
txt = txt+replaceword;
} else {
txt = txt+b_text.charAt(char);
}
char = char+1;
} while (char<b_text.length);
return (txt);
}
//End Code (Z.24)
this.onPress = function() {
txt = "";
_root.s_text = "";
_root.s_text = search(_root.b_text, _root.keyword, _root.replaceword);
};
}

OK, the scripting is not the best, but i had only little time

so what does it do?? it checks a text for a keyword and replaces it by another! Maybe, it can be used to replace Objectnames in a script, by newer ones (or variables)
Example:
Keyword: Nobody
Replaceword: McGiver
Text: Nobody is perfect! So Nobody will beat me!blablaNobodybla
Output: McGiver is perfect! So McGiver will beat me!blablaMcGiverbla

BUT: the replacinator 2050 (thats how i call my masterpiece
;) ) will not replace words with (don't know how it's called in english) differend "size" of the Letters
Example:
Keyword: BLA
Replaceword:yyy
Text: xxxxxblaxxxBLAxx
Output: xxxxxblaxxxyyyxx

wanna see it in action?
Replacinator 2050 (http://de.geocities.com/roland_plass/replacinator2050.html)

linckx
04-24-2003, 09:27 PM
nice mcgyver thing...

you mean it is not case sensitive?

robin

McGiver
04-24-2003, 10:12 PM
Thanx!
sensitive? you mean because it makes a difference between "A" and "a"?
I saw no chance to solve that problem within 25 lines of script (the function took 21 lines i think, so i do not see a chance to do it in 4 lines :( )


to all other scripters: please pose a swf file in the net to let the other see what you have done. I do not have the time to try every script on my own
And, like Jessy said, the Design doesn't matter, only the script is important, so it doesn't have to look very beautiful if you do not have the time!

McGiver
04-24-2003, 10:30 PM
to Jessy: I have an Idea for the next contest:
to design a cool Award for the contests (with 25 or less lines of script):D

tost
04-24-2003, 10:33 PM
a client requested to be able to use <b> and <i> tags to format text in a scroller. the problem was that, using substring, tags are cut as the next char moves to the end, eg: theText = "i>italic text</i><";
this caused tags to be partially visible sometimes, formatting flashed from bold to plain and the text jumped a few chars, here's my fix:

the code checks for <i> or <b> tags,
if one is found at the beginning, move the complete tag to the end,
add a temporary <b> or <i> tag in the beginning untill a </b> or </i> is found,
move the complete </b> or </i> tag to the end.

i attached the fla, there's a version with comments and trace commands to see what happens and a stripped version like here:


function moveChar(numChars) {
firstPart = theText.substring( 0, numChars );
secondPart = theText.substring(numChars, theText.length );
theText = secondPart + firstPart;
}
function scrollText() {
if (cutting_bold==true){
theText = theText.substring(3, theText.length );
}
if (cutting_italic==true){
theText = theText.substring(3, theText.length );
}
firstChar = theText.substring( 0, 1 );
secondChar = theText.substring( 1, 2 );
thirdChar = theText.substring( 2, 3 );
if (firstChar == "<"){
if (secondChar == "b"){
cutting_bold = true;
moveChar(4);
} else if (secondChar == "i"){
cutting_italic = true;
moveChar(4);
} else if (secondChar == "/" && thirdChar == "b"){
cutting_bold = false;
moveChar(5);
} else if (secondChar == "/" && thirdChar == "i"){
cutting_italic = false;
moveChar(5);
}
} else {
moveChar(1);
}
if (cutting_bold==true){
theText = "<b>"+theText;
}
if (cutting_italic==true){
theText = "<i>"+theText;
}
}
theText = "plain text <b>bold text</b> plain text <i>italic text </i>"
scrollInterval = setInterval(scrollText, 50);


cheers :)
tost

tost
04-24-2003, 10:36 PM
oops
lost the attachment while previewing the post
here it is :)

buggedcom
04-27-2003, 06:44 PM
very nice. however i would like it even better combined with xxlm enterInvert one.

tost
04-27-2003, 08:17 PM
can't seem to find what you mean, got a link?

buggedcom
04-27-2003, 08:48 PM
my apologies to pom and xxlm and yourself it's actually by pom in this thread.


// copyright pom, just in case you want to steal this little wonder
TextField.prototype.enterInvert = function(str){
var mc = _root.createEmptyMovieClip("controller",1000001);
mc.ref = this;
var count = str.length;
controller.onEnterFrame = function(){
if (count > 0){
var a = str.slice(count-1,count);
count--;
this.ref.text = a + this.ref.text;
}
}
}
this.createTextField("myText",0,50,100,400,20);
myText.enterInvert("ilyas est vraiment trop fort");

buggedcom
04-27-2003, 08:50 PM
i tried to do it myself, but got lost in for loops and sting functions :/

also i got so much to do so i stopped :/

farafiro
04-29-2003, 06:09 AM
ilyas est vraiment trop fort hmmmmmmmm
oh, really??

pom
04-30-2003, 02:18 PM
Oh yeah! Let's combine our scripts :)Originally posted by farafiro
hmmmmmmmm
oh, really?? :rolleyes: :rolleyes:

farafiro
05-04-2003, 06:12 AM
Originally posted by pom
Oh yeah! Let's combine our scripts :) :rolleyes: :rolleyes: deal
where and when??

Jesse
05-10-2003, 01:04 PM
Time to run another of these, but first we need concepts in one central thread:
http://www.actionscript.org/forums/showthread.php3?threadid=27694