767 posts
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
outandouter says

I turned out to explain my problem in quite a lot of words. Please don’t hesitate to read. :)

Hey Guys,

In a project, I have quite a lot images which are parts of buttons, backgrounds, and a couple of different modules. The dimensions of these buttons, backgrounds are dynamic. I need the image to actually fit the whole area of the buttons and fill the backgrounds keeping their proportions which can be any. For that I have written a function which gets the image’s dimensions and button’s/background area’s dimensions and returns a calculated width and height to exactly fit the image inside that area keeping its proportions.

I have several classes, one for each module(button, background and others). I need that same function everywhere.

Now, I was thinking if there could be a way that I can create a Class inside which I could put that function and use that universally but it is not possible to return values from a function within class without using “get” with that function. So, when I use “get”, I get an error that a getter function can not have parameters.

What could be my best bet on this?

By the way, I would like to call that function this way:

myWidth = getWidth(this.width, this.height, button.width, button.height);
myHeight = getHeight(this.width, this.height, button.width, button.height);

- Kamil Waheed

569 posts
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
jayc says

No man, what you need is a generic container class, than all your classes will extend that class (your generic container class will have your required function therefore all the classes that extend that generic class will have that function).

I have made such a class for me (similar to Flex UIContainer) to ease up my work, you can take a look at my class here http://pastie.org/1019724 .

Best regards, JayC

569 posts
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
jayc says

Now in my case every container that I make it extends UIContainer like:

class ImageModule extends UIContainer

767 posts
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
outandouter says
No man, what you need is a generic container class, than all your classes will extend that class (your generic container class will have your required function therefore all the classes that extend that generic class will have that function).

I have made such a class for me (similar to Flex UIContainer) to ease up my work, you can take a look at my class here http://pastie.org/1019724 .

Best regards, JayC

Oh, yea. This is exactly what I needed. Thanks!

5277 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
+5 more
CodingJack says

I don’t know if this will help but you don’t need to use “get” to return a value from another class.

4136 posts
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
tsafi says

Cj is right ”’get” “set” is not something mandatory its just something that help us the way we structure our class and something we use according to our coding style.

So its really something the way you are coding, many don’t use this method, its just something you evolve in the way you are coding, for me get set is to simplistic the way i pass my id verb on the return function on the extend class, but there are many deference ways to do it ,usually i avoid get set on the same class but again its up to the way you code on the fly

by
by
by
by
by
by