View Full Version : back to the ball, want to understand
subquark
07-13-2003, 12:46 PM
Ball._x = 20;
Ball._y = 20;
moveBall = function(){
this._x += this.speed;
this._rotation += this.spin;
if (this._x <= 20){
this.speed += 5;
this.spin += 10;
}
if (this._x >= 380){
this.speed -= 5;
this.spin -= 10;
}
}
Ball.speed = 5;
Ball.spin = 10;
Ball.onEnterFrame = moveBall;
So why do I have to declare Ball.speed and Ball.spin outside of the function? I realize that makes them variables, but how do I clean this up since there seems to be some redundancy.
At least now I don’t lose my ball ;p
Billy T
07-13-2003, 12:58 PM
doing it like that makes your function more flexible...you can have multiple clips all using the same function but moving and spinning at different speeds
ya dig?
subquark
07-13-2003, 01:28 PM
Thanks Billy T! So I could have ballOne, ballTwo and so on. Okay, I get that, but how does the Ball.speed = 5; interact with the code this.speed += 5;? Does it add the two together so that the actual speed is 10?
CyanBlue
07-13-2003, 01:45 PM
Try this...moveBall = function ()
{
this._x += this.speed;
this._rotation += this.spin;
if (this._x <= 20)
{
this.speed += 5;
this.spin += 10;
}
if (this._x >= 380)
{
this.speed -= 5;
this.spin -= 10;
}
}
Ball1._x = 20;
Ball1._y = 20;
Ball1.speed = 5;
Ball1.spin = 10;
Ball1.onEnterFrame = moveBall;
Ball2._x = 20;
Ball2._y = 80;
Ball2.speed = 10;
Ball2.spin = 15;
Ball2.onEnterFrame = moveBall;And, naming the ball as ballOne and ballTwo is not such a good way especially when you have to enumerate them with the for loop...
Ball1 has its speed set to 5 and the moveBall() function adds 5 to it which makes 10...
Ball2 has its speed set to 10 and the moveBall() function adds 5 to it which makes 15...
and so on... ;)
Why suddenly OOP though??? ;)
subquark
07-13-2003, 01:51 PM
Why suddenly OOP though??? what do you mean? You mean ActionScript? I need to become a GURU like you and have the rest of the day. Can I do it and still have time for dinner?
Thanks for the explanation, but how would I leave this.speed += 5; without a value in it? Put this is this.speed += 0;?
subquark
07-13-2003, 01:56 PM
enumerate them with the for loop... for (i=0; i<5; i++){
nm = "ball" +i;
ball.duplicateMovieClip (nm, i); like that? That way I make 5 balls?!?!:confused:
CyanBlue
07-13-2003, 01:57 PM
what do you mean? You mean ActionScript?No, I mean OOP... :) I need to become a GURU like you and have the rest of the day. Can I do it and still have time for dinner?Well... That depends on how you define the Guru... If you mean somebody like me, then, yes... You will have plenty of time to prepare the dinner afterwards... But if you mean somebody like senocular or freddycodes, then, um... Forget about the dinner for the lest of our life... Matter of real or fake Guru it is... :)but how would I leave this.speed += 5; without a value in it? Put this is this.speed += 0;?What do you mean??? :confused:like that? That way I make 5 balls?!?!Yup... Exactly... :)
subquark
07-13-2003, 02:08 PM
what is the difference between OOP and AS?!?!:confused: Why is my little function OOP? What would it look like in AS??!!:confused:
for the speed thing, If I say this.speed +=0; then whatever I declare for speed in variable will add to 0 right?
BTW, you are GURU, MM says so. :D
CyanBlue
07-13-2003, 02:12 PM
what is the difference between OOP and AS?!?! Why is my little function OOP? What would it look like in AS??!!The difference between OOP and the AS??? OOP is a certain way or method of programming, and AS is the programming language itself... So, how you program vs what you use to program, or something like that???for the speed thing, If I say this.speed +=0; then whatever I declare for speed in variable will add to 0 right?Um... Yes... But why would you want to do that??? Then, it won't change anything at all... BTW, you are GURU, MM says so. Time to go get some more M&M chocolate then... :)
subquark
07-13-2003, 02:21 PM
But why would you want to do that??? Then, it won't change anything at all... well if I set it to 5, then that five is always added to the variable right? So If ball1.speed = 10; than it really goes 15 right? So with 0 in the function, when Ball1 is set to 10, the real speed will be ten, right? :confused:
OOP is verbal communication, French is language, got it. Thank you GURU CYanBlue (oh oh, that rhymes, you know what happened last time). Did you see my resume, Retrotron liked it (from a design view) and the text was reworked by Kennedy. Would like me and/or Kennedy to do yours? www.subquark.com/david
CyanBlue
07-13-2003, 02:34 PM
So, you want to keep it the way it is as it is declared in the beginning??? Try this...moveBall = function ()
{
this._x += this.speed;
this._rotation += this.spin;
if (this._x <= 20)
{
this.speed = this.speed * -1;
this.spin = this.spin * -1;
}
if (this._x >= 380)
{
this.speed = this.speed * -1;
this.spin = this.spin * -1;
}
}
Ball1._x = 20;
Ball1._y = 20;
Ball1.speed = 5;
Ball1.spin = 10;
Ball1.onEnterFrame = moveBall;
Ball2._x = 20;
Ball2._y = 80;
Ball2.speed = 10;
Ball2.spin = 15;
Ball2.onEnterFrame = moveBall;The resume... Yeah... I have seen it last time... I thought that I had commented on that, I guess not??? The font in the SWF file is abit too small for my eyes... Rather than that, yeah... Cleaner and easier to see the blocks on the layout... Yeah... I could use some help on the resume... But I am not in such a hurry, so do that when you have free time... Probably when things get settled abit... ;)
subquark
07-13-2003, 03:02 PM
hmm, so you are multiplying by one, isn't that the same as adding "0" in this case?
10 X 1 = 10
10 + 0 = 10
Not trying to be difficult, just want to make sure I develop a GURU style following in your footsteps. :p
The resume swf is the swf output from FreeHand and is Verdana set at 8. So why is it legible at all? If I make swf with Verdana 8, it don't look like that!?! :confused:
CyanBlue
07-13-2003, 03:07 PM
I haven't actually tried that but if you set it to 0 instead of -1, it will just go to one direction and won't come back... Try it and let me know??? ;)
As for the font, I have no idea how it works with Freehand... Aren't the font size supposed to be the same when they are used within the same Macromedia products at least??? Hm...
subquark
07-13-2003, 03:15 PM
doh! of course, it would not work the way I am saying because I am using += and -=, so the multiplier is a far better way.
CyanBlue is MM GURU!
CyanBlue
07-13-2003, 03:26 PM
You are silly sometimes... :p
subquark
07-13-2003, 06:12 PM
okay, what is wrong here :confused: hopMe = function (){
this._y += this.hop;
if (thix._y >= 0){
trace ("Y position " + bob._y);
this.hop += 5;
}
if (this._y <= 300){
trace ("woe, there goes the lower limit");
this.hop -= 5;
}
}
bob._y = 15;
bob.hop = 5
bob.onEnterFrame = hopMe; and when it goes below 300, it hauls butt! It's almost dinner time and I am still not CyanBlue GuRu material . . . :(
last I checked bob was here: Y position 805430, I think he almost to Korea?!?!
CyanBlue
07-13-2003, 06:31 PM
Look at this script and the output of it...hopMe = function ()
{
this._y += this.hop;
trace("this._y = " + this._y + "\t\tthis.hop = " + this.hop);
if (thix._y >= 0)
{
// trace("Y position " + bob._y);
this.hop += 5;
}
trace("this._y = " + this._y + "\t\tthis.hop = " + this.hop);
if (this._y <= 300)
{
// trace("woe, there goes the lower limit");
this.hop -= 5;
}
trace("this._y = " + this._y + "\t\tthis.hop = " + this.hop);
};
bob._y = 15;
bob.hop = 5;
bob.onEnterFrame = hopMe;this._y = 20 this.hop = 5
this._y = 20 this.hop = 10
this._y = 20 this.hop = 5
this._y = 25 this.hop = 5
this._y = 25 this.hop = 10
this._y = 25 this.hop = 5
this._y = 30 this.hop = 5
this._y = 30 this.hop = 10
this._y = 30 this.hop = 5
...
...
this._y = 300 this.hop = 5
this._y = 300 this.hop = 10
this._y = 300 this.hop = 5
this._y = 305 this.hop = 5
this._y = 305 this.hop = 10
this._y = 305 this.hop = 10
this._y = 315 this.hop = 10
this._y = 315 this.hop = 15
this._y = 315 this.hop = 15
this._y = 330 this.hop = 15
this._y = 330 this.hop = 20
this._y = 330 this.hop = 20
this._y = 350 this.hop = 20
this._y = 350 this.hop = 25
this._y = 350 this.hop = 25You have two if blocks in your code, and the first and the second if conditions are met true if (0 <= this._y <= 300) and in case if (this._y > 300) you are keep increasing this.hop by 5 from the first if block... So, you have one routine of two if blocks that is keeping this.hop to be the same value until this._y <= 300, and another routine keep increasing the this.hop once that stage is passed... Know what I mean???
subquark
07-13-2003, 06:54 PM
oh brother, my Matematics minor is definately a past thing! Okay, let me try to get this thing to move up and down (gee, it's just like the ball going side to side). So now you see the real truth . . . :p
freddycodes
07-15-2003, 02:53 PM
If I might chime in here. OOP like CyanBlue said is a method of programming, it is very in depth and too much to go into with this thread. But there are various rules for using OOP like data encapsulation. Not directly chaining object properties from outside the class, blah, blah...
A better way to write the ball example might be.
function Ball(x,y,speed,spin,depth) {
this = attachMovie("ball", "ball"+depth, depth);
this._x = x;
this._y = y;
this.spin = spin;
this.speed = speed;
this.onEnterFrame = moveBall;
}
moveBall = function ()
{
this._x += this.speed;
this._rotation += this.spin;
if (this._x <= 20)
{
this.speed = -this.speed;
this.spin = -this.spin;
}
if (this._x >= 380)
{
this.speed = -this.speed;
this.spin = -this.spin;
}
}
Ball1 = new Ball(20,50,30,15,0);
Ball2 = new Ball(20,100,20,50,1);
So function Ball() is our constructor function where we pass arguments to the constructor function. It creates the object and assigns the initial values to the object.
ball is a movie clip with linkage of "ball" I just used a simple oval shape for the movie clip in this example.
So when we create a new instance of the ball class, it attaches the mc assigns the initial properties then assigsn the onEnterFrame handler.
Billy T
07-15-2003, 08:19 PM
nice one freddy
just out of curiousity, when you come to work on a job...say a small website...do you code like that (OOP)?
freddycodes
07-15-2003, 08:25 PM
I try to, always when I need to reuse functions and organize multiple objects of the same type.
CyanBlue
07-15-2003, 08:32 PM
Ahhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!
freddycodes did subquark's homework... :(
I was going to have him suffer for 7 more days with this, but freddycodes did it for him... :(
:)
Nice code, freddycodes... I think the code shows exactly what OOP is... Nice and clean... ;)
Billy T
07-15-2003, 08:33 PM
makes sense....
hey can I hijak this thread and ask you a php question freddy? too late.... :p
remember that search engine thing I was making? well my script scans all the content pages and returns the results - this works well. But the problem is that it returns the name of the file for the link (eg home_people_24D)...not very pretty. What I want is to be able to grab the title of the that page and return that instead
I'm thinking the best way to do it (the pages that get scanned dont have a title tag) would be to put something like
<!--pageName=My Home Page-->
in the first line of every page
What I want is to be able to extract 'My Home Page' or whatever the title is to use it as the link
easy peasy?
:p
freddycodes
07-15-2003, 08:37 PM
So you say that they do not have title tags?
Well in order to pull this off you would need to re the entire contents of the page into a variable and then use regular expressions to pull the value out. Are you currently reading in the entire contents of the files to a variable in order to do your search?
subquark
07-15-2003, 08:40 PM
wow! freddycodes! that is a good explanation! I like the way you set up that function. I like the way you set up the variables in the function. So I can do something like this:function BlahBlah(x,y,speed,inertia,momentum, colour, spitze, etc) { right? Anything goes in the () as long as I address it later right? But I get confused with things like "inertia", can it be anything? Or does it have to be things like "speed" and "spin" which is related to rotation?
Am I making sense? I can sort of understand your "way", it makes sense to me, and at this early stage of my OOP learning, the way I feel is best, and I learn, will be the way I will program the rest of my life. So it is important to establish good habits from the start. Thanks, your words are valued tremendously and respected by me. Thanks. :)
btw, spitze means terrific in german I think
Billy T
07-15-2003, 08:46 PM
Originally posted by freddycodes
Are you currently reading in the entire contents of the files to a variable in order to do your search?
yep
$fp = fopen("content/$pages[$i]", "r");
$data="";
if($fp) {
while(!feof($fp)) {
$data .= fgets($fp, 1024);
}//end while
freddycodes
07-15-2003, 08:57 PM
Okay so here is what you would need after the while() loop.
preg_match("/pageName=([^\-]+)/", $data, $match);
$title = $match[1];
print $title;
Billy T
07-15-2003, 08:58 PM
Thanks!!
I'll try it now :D
Billy T
07-15-2003, 09:30 PM
working beautifully!!
Thanks freddy
(now I gotta read some more about regular expressions....fun fun)
Billy T
07-15-2003, 10:14 PM
small update
the code above was stuffing up when there was a page title with a - in it
eg
the story - to be continued
was coming back as 'the story' so I changed the code to
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
and it seems to be working nicely. However, I am very unsure about what the hell I'm doing with these expressions - does that code look ok to you?
Thanks again
Billy T
07-15-2003, 10:16 PM
wtf? code got formatted when I posted it...
will try again
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
Billy T
07-15-2003, 10:17 PM
first one is what I have
That's a pretty crappy bug in the forum...I'll email jesse
Jesse
07-15-2003, 10:49 PM
Hmm I see the problem but I don't know if it's fixable. It comes from the escaping of coded segments to prevent attacks on the board I think... I'm sure it IS fixable, but whether or not we have thte time to trall through the formatting scripts is another issue. The code tag shold work though:
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
Billy T
07-15-2003, 10:56 PM
Originally posted by Jesse
The code tag shold work though:
preg_match("/pageName=(.*)\-\-/", $data, $matchName);
ahh ok well that's good to know
cheers
freddycodes
07-15-2003, 11:18 PM
Yeah this is pretty much the same. See you are getting it.
preg_match("/pageName=(.+)\-\-/", $data, $match);
Billy T
07-15-2003, 11:23 PM
cool
so having
.+
instead of
.*
means that at least 1 character will be returned - is that right?
freddycodes
07-15-2003, 11:55 PM
YEp and actually this would be more correct I think
preg_match("/pageName=(.*)[\-]{2}/", $data, $matchName);
Billy T
07-16-2003, 12:26 AM
yeah I was playing around with {2} but had the syntax all wrong
hey I just found a problem...if you go here
http://billyt.homeip.net:81/james/main.php?page=home
and search for 'ant'
you will see the last result includes the --> in the title name
just happens with that file...really strange
any ideas?
Thanks again
freddycodes
07-16-2003, 12:35 AM
If you view the source of that html page that is linked to the one with --> at the end, you'll see in the html right after
"We don't believe this guy's story
There is a --
so it was being greedy.
Try this
preg_match("/pageName=(.+)[\-]{2}>/", $data, $match);
The reason it did that only on that page is, that was the only plage with a -- in the content. NOw it will only match on -->
Billy T
07-16-2003, 12:43 AM
yeah well I'm sure I would have figured that out myself within the next million years!!
Thanks again freddy - you're a gun!!
Billy T
07-16-2003, 12:46 AM
quick question
how do I stop it searching after it finds one result? I just noticed that other
<!--comments--> on the page stuff it up as well
Thanks
Billy T
07-16-2003, 01:01 AM
yay I fixed
I punished the script for being greedy by changing the
.+
to
.+?
:p
subquark
07-16-2003, 02:31 PM
holy smokes! :eek: the ball got real complicated. so I take it we have a dual thread thing going on here!
Back to what Billy T said: just out of curiousity, when you come to work on a job...say a small website...do you code like that (OOP)? I'm confused about that statement, wouldn't you always approach even a small site project like that?
Or is the OOP approach considered (by you guys) as a more advanced thing in flash? I'm asking because there seems to be a real separation by "folks" between doing flash and doing OOP in flash.
Billy T
07-16-2003, 08:14 PM
Originally posted by subquark
wouldn't you always approach even a small site project like that?
depends what you are used to. I'm not comfortable scripting OOP so if its a small job then I just revert back to 'messy as all hell but get the job done' style of coding.
If its a BIG job then I like to use my patented 'messy as all hell but get the job done and then add a few comments so it makes some sense later' style of coding...
Billy T
07-16-2003, 08:16 PM
oh yeah and sorry for hijaking your fred...I mean thread...
subquark
07-16-2003, 08:26 PM
sorry, you must have the wrong Fred, he's right here by my feet. Fred is a 14 year old Australian Shepherd and a big sweetie pie. We took in an abandoned kitty and he became an overly protective mom, even 8 years later.
Hey! Fred, where did you go!?!! Okay, I'll give you back Crunchy if you give me back Fred. :D
So anyway, back to OOP. So do you conider your Smooth Transitions scripting to be OOP or is that something really simple for you (keep in mind I get disparaged easily and start to drink ):p
freddycodes
07-16-2003, 08:34 PM
What the one I showed in this thread? Yeah I would say its pretty close to OOP. OOP takes on some definite charactersistics, data encapsulation for one. I would suggest reading some tutorials on OOP basics, then you can show up a hack like me who pretends to know way more than he really knows. I have a 15 lb Maine Coone Cat downstairs named freddy.
Billy T
07-16-2003, 08:35 PM
Originally posted by subquark
[B]keep in mind I get disparaged easily and start to drink
LOL
nah that aint OOP but it works so who cares? I'll have a martini thanks...
btw you can't have your dog back...its doing all my php/mySQL work at the moment. Maybe in a few months
cheers
Billy T
07-16-2003, 08:37 PM
Originally posted by freddycodes
What the one I showed in this thread?
I think he was talking about this (but you never can be sure with these alcoholics...) - http://www.tableau.com.au/tutorials/smooth_transitions/
freddycodes
07-16-2003, 08:42 PM
Oh, stop referring to fred in this thread, I think yo uare talking to me.
Billy, I will repsond to your PM in a few. I have a few samples.
subquark
07-16-2003, 08:43 PM
hack like me who pretends to know way more than he really knows oh great! if you are an example of that, I need to buy a lot more gin!!! :D
so Billy T, your Smooth Transitions coding is not considered OOP? :confused:
Is OOP just pure programming like C++?
subquark
07-16-2003, 08:45 PM
stop referring to fred in this thread, I think yo uare talking to me only if you burp alot, lick your own butt and shed alot! :D
freddycodes
07-16-2003, 08:46 PM
Hey are you spying on me!
Billy T
07-16-2003, 08:49 PM
Originally posted by freddycodes
I have a few samples.
awesome thanks Freddy.
subquark
07-16-2003, 08:49 PM
:D our dirty little secret, shh . . .
Billy T, you want a vodka or gin martini?
Billy T
07-16-2003, 08:51 PM
Originally posted by subquark
your Smooth Transitions coding is not considered OOP?
nOOPe
I have a book on OOP in flash...will lend it to you if you pay for postage
cheers
Billy T
07-16-2003, 08:52 PM
Originally posted by subquark
Billy T, you want a vodka or gin martini?
just give me the bottles...
subquark
07-16-2003, 09:03 PM
what's the title? i have Moock's book, is that OOP? are functions OOP?
http://www.subquark.com/footer/martini2.gif
Billy T
07-16-2003, 09:07 PM
thanks for the drink...just what I needed at 10 in the morning...
there is some stuff on OOP in moocks book. using functions doesnt automatically make your code OOP
The title of the book is "OOP with Actionscript" - sound appropriate? ;)
cheers
subquark
07-16-2003, 09:11 PM
http://www.amazon.com/exec/obidos/ASIN/0735711836/wheelmaker-20/103-1844031-8515022
if that's it, no need to answer. I'll order it tonight. Thanks. Oh, 10 in the morning, well, better have a Bloody Mary then . . . :)
Billy T
07-16-2003, 09:13 PM
Originally posted by subquark
I'll order it tonight.
from me or amazon?
yep that's the book
cheers
CyanBlue
07-17-2003, 01:43 AM
Yeah... That's the book I was going to buy as well... ;)
Somebody from this forum sent me some Amazone gift card the other day and I was meaning to order the book with that... I am waiting for another gift certificate at the moment from one of those click-to-accumulte-the-point site, and as soon as that one clear up, I'm going to get that book as well... ;)
Billy T
07-17-2003, 01:47 AM
Originally posted by CyanBlue
Somebody from this forum sent me some Amazone gift card the other day
no ****?
Billy T
07-17-2003, 02:01 AM
freddy - did you forget about me? ;)
CyanBlue
07-17-2003, 02:11 AM
no ****?Huh??? No what???freddy - did you forget about me?Give him some time to sleep... :p
Billy T
07-17-2003, 02:21 AM
Originally posted by CyanBlue
Give him some time to sleep... :p
freddy isn't human...he doesnt need sleep
I said "no sh!t?" someone gave you a gift for helping em out here?
CyanBlue
07-17-2003, 02:39 AM
freddy isn't human...he doesnt need sleepI agree with the first part, but not the second part... :)I said "no sh!t?" someone gave you a gift for helping em out here?Yeah... A nice guy did that... :)
stealthelephant
07-18-2003, 04:14 PM
after seeing references to the ball all over the forums, could u post the code so we can actually get to see your ball in action?
Timmee_3Styler
07-18-2003, 04:21 PM
im not sure subsquark can do that cause I was told that the ball is halfway around the world already
stealthelephant
07-18-2003, 04:37 PM
no problemo!
trace(ball._x);
trace(ball._y);
CyanBlue
07-18-2003, 07:41 PM
Haha... Funny!!! :)
But I think you need to use the new properties to get the right coordinates of the ball half way across the world...trace(ball._longitude);
trace(ball._latitude);By the way, I think subquark's ball probably have met another cute lady ball...
That's why it still is half way across the world and not coming back... :)
subquark
07-18-2003, 08:14 PM
subquark's ball probably have met another cute lady ball he he, another happy ending! :D
subquark
07-18-2003, 08:18 PM
could u post the code so we can actually get to see your ball in action? Ball._x = 20;
Ball._y = 20;
moveBall = function(){
this._x += this.speed;
this._rotation += this.spin;
if (this._x <= 20){
this.speed += 5;
this.spin += 10;
}
if (this._x >= 380){
this.speed -= 5;
this.spin -= 10;
}
}
Ball.speed = 5;
Ball.spin = 10;
Ball.onEnterFrame = moveBall;
just make a ball with a gradient, call it ball and voila! I bet this will be the most downloaded file ever! :p Hope the server bandwidth can handle it!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.