Tuesday, July 14, 2009

OOP is my friend

I have been building applications using more 'object oriented' techniques. An old dog like me who grew up coding basic, keying in machine code and the sort, may have trouble adapting to new methods.

After page upon page of confusing examples of inheritance, encapsulation, polymorphism and other oop terms, i decided to take some advice of a colleague and break it all down to the simplest parts. So I did and I think the fog is clearing a little concerning OOP.

Some tips about grasping oop:

1) Everything is an Object

2) Classes are blueprints

3) Extending a class opens up all of those methods to your new class, build on that foundation

4) An object does not exist util instantiated

5) OOP is a tool, it cannot replace procedural programming

OOP programming comes in many shades of gray, for this post lets consider that oop procedures are accomplished through the creation of Actionscript 3 class packages , hence objects. Each object is responsible for one thing, being itself.

Program for me a candle.

I would package an actionscript class called Candle . Within this actioncript file I would procedurally program the functionality of a candle. The candle should react to things just like a real one. Create a function
lightIt();
You call the function the candle brightens the room. The amount of functionality is totally up to you, the "object creator". There is no limit, your candle object could react to being left in the sun or even relight like a joke birthday candle. Just be sure that you don't go to far. Make the candle as basic as possible and extend it into new child classes, like a birthday candle class that extends Candle. You can always make objects more complicated , start simple.

Now store your candle in your special package directory and call upon it any time in the future when you need an object like a candle. Build upon objects, add functionallity simply and quickly, and then interact with other objects that you have created.

Friday, July 10, 2009

Game Archive and Review

Check out these game reviews and play our daily free flash game picks on the Hyperspatial web site!

About to go Live with Avangate

I am about to kick off my software selling endeavor through Avangate. I am very pleased with the experience so far. Avangate is a multi national software vendor. It was easy to setup my account and customize the shopping cart to match my web site's look with css. They set up a pre payed master card that arrived in the mail within a few days of joining up.
They work on a commission system with no monthly fee. I am very happy with their support team and hope to do business with them for a long time.

I am hoping to reach customers across the globe. Right now I am selling my nature sounds player that I created on the Adobe Air platform using As3, the program is absolutely fabulous. Check it out here

I am working on setting up my banners and pad files for my affiliate program right now and I will post some links to check out in a couple of days for you to join my affiliate program through Avangate. I have not decided on a commision yet but I will probably offer somewhere in the vicinity of a 20% commision on sales. All you have to do is sign up as an affiliate and put one of my .jpg images on your web site or blog as a link. The user's browser stores a cookie for 4 months that tracks their purchases of my software and then if they buy, you get the commision.

I will keep you posted.

Tuesday, July 7, 2009

Transparent SWF

I was creating a .swf file player for my website. The player is used to prevent the annoying "autoplay" that tend to be difficult to stop. Some flash games are setup so there is no easy way to prevent this, hence your page opens up and plays the game soundtrack right away. Sorry I need to control that, even setting javascript control for the flash to param play="false" does not always work.

Anyway, the .swf file I created that plays .swf files when you click on the play button. The problem I had was that I set the player to
param wmode="transparent"
this caused games controlled by the arrow keys to scroll the browser at the same time. That makes it impossible to play the game.

Moral = If you load a swf into another swf that is transparent you may have issues with browser scrolling

points and pixels

points = pixels * 72 / 96

75 = 100 * 72 / 96

pixels = points * 96 / 72

100 = 75 * 96 / 72

Vista and air

When you try to direct download an .air file via adobe air and ie7 or 8 on your vista os it will think that the air file is a zip file. The solution is simple, change the extension to .air

You can also do it the right way and set up an air badge to properly install the air program.

Object stuff

Just adding some of my daily epiphanies.

The ability of As3 to just assign description strings "I call them", to objects is as handy as a four armed butler. If you need some kind of switch in your program you don't necessarily need to declare a public variable to use as a switch. It is very simple to just add a string to an object. My object is Player. just add dot syntax and:

player.state = "off";

For the newbies you can add anything you want to your object, real time, like this:

player.happynessiocity = "groovy";

Makes for an easy conditional to check a condition, like this:

if(player.state == "off")
{
}


This is a bit of a hack and it throws a swf error but runs. Maybe will work in a pinch but here is a clever solution for a switch in a case where event flow won't allow you to access a listener somewhere. Just change the name of the button.

player.name = "off";

You are effectively negating listeners of parent display object containers elsewhere until you return the name to normal:

player.name = "playbutton";

Concerning functions, it is very handy to be able to send a function an object. You can then mass produce object modifications, like alpha, scale, with dot syntax. Just pass the function the object and then change it:
changeTheSize(myObject);

function changeTheSize(obj:myObject):void
{
obj.scaleX = 1.5;
obj.scaleY = 1.5;
}


You can create factories this way and just send in anything you want to make bigger, or whatever.

Math.round decimal places

Here is some rounding help. This converts miliseconds to seconds with two decimal places. Note the "/10) * 10" part, that rounds it to 2 decimal places, "/100) * 100" would round it to one decimal place.

_secondsRound = Math.round(_theSound.length / 10) * 10 / 1000;

Set Focus

Just sharing some info about focus in As3.

Opon experimenting with text input boxes I discovered that setFocus(), when uses on a hidden text input box was a great way to hide a cursor after ENTER event.

drawFocus() also comes in handy to bring a field back into perspective.

Top of display list

Example of setChildIndex to bring your display object to the top.

import flash.display.Sprite;
import flash.events.MouseEvent;

var container:Sprite = new Sprite();
addChild(container);

var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFF0000);
circle1.graphics.drawCircle(40, 40, 40);
circle1.addEventListener(MouseEvent.CLICK, clicked);

var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0x00FF00);
circle2.graphics.drawCircle(100, 40, 40);
circle2.addEventListener(MouseEvent.CLICK, clicked);

var circle3:Sprite = new Sprite();
circle3.graphics.beginFill(0x0000FF);
circle3.graphics.drawCircle(70, 80, 40);
circle3.addEventListener(MouseEvent.CLICK, clicked);

container.addChild(circle1);
container.addChild(circle2);
container.addChild(circle3);
addChild(container);

function clicked(event:MouseEvent):void {
var circle:Sprite = Sprite(event.target);
var topPosition:uint = container.numChildren - 1;
container.setChildIndex(circle, topPosition);
}

Variable behaviors

While working with public variables within a custom class i had the following observations:

Created a new TextField in the constructor function and change the variable.text in another function by mouseclick. The result was that the textfield was updated at each mouse click.

Conversely if you create the TextField within the mouse click event handler function the textfield keeps placing text on top of text each time the mouse is clicked.

Conclusion, creating TextField by a function variable stacks instance upon instance instead of just changing the single "public variable" each time the mouse is clicked. Might be handy for adding a bunch of graphics on top of one another in the display list.

As3 tool

Here is some code to check the name and object class of buttons you click on in your project. The function is great for troubleshooting.
Notice that the up and down "volume" buttons return a target of [object VolUp] but they each have their own instance names "down and up". This is because I used the same symbol-"class" for both instances. Great for learning/finding errors.
Also notice you can click on the unnamed movieclips(level bars) and it displays their instance names.

The code snippet is the function that displays mouse click info. You will need to format the TextField to get it to display where and how you want it.( _text.width = 400;) for example.




Click anywhere on the player face above.
var _text:TextField = new TextField();

//testfunction
public function testIt(evt:MouseEvent):void
{
_text.text = "Event:\n" + evt + "\n\nClicked target = " +
evt.target + "\nClicked target name = " + evt.target.name;
addChild(_text);

trace("Ran button test:");
trace("clicked target = " + evt.target);
trace("clicked target name = " + evt.target.name)
}

Access display object name


Recast event as a display object to access the name string:
catching a mouse event name

trace(DisplayObject(evt.target).name)//displays object instance name, like button1

Function of parent MC

To call a function of a parent movie clip:
set variable to as MovieClip before you can access parent

var theVName:MovieClip = this.parent as MovieClip;
theVName.doSomething();

Comment of the day

Hazza, I love you As3

Class function com

Seems through experimentation that within classes it is impossible to access public class variables outside of a function, period. Public variables are accessible from document class but only from within its functions, not code within the class brackets.
Public variables get declared within the class brackets.

Combo box tip

Just stumbled upon a combo box issue that might boggle ya. When adding listeners for keyboard KEY_DOWN type events you may run into trouble when opening a combo box. It may disable your key pressed listener.
Solution is simple. The Combo box draws focus away from the stage because it has its own keyboard commands for navigating the combo box. It gets left on even after your selection. Solution =
someObject.setFocus()
to draw focus away after combo box dropdown closed or a selection made.

Test Input field quirk

Along the same lines of the last post about combo box focus and its issues, here is a Text input field issue I found.
If you are listening for keyboard events be aware that whatever text input field has focus on it will pick up the key pressed in its field. It's weird too, you can't get rid of it even by setting the field's text to nothing.
textfield.text = "";

If you set the text to something else the key you hit still occupies the first slot, shaky bug. To avoid it make sure that even when invisible, make sure that no text input fields have focus on them. You could set up a hidden 'ghost' field to have focus on if you need to send focus elsewhere.

Links to Flash help

Tutorials
http://www.kirupa.com/
http://www.lionbichstudios.com/flash_tutorials_01.htm http://www.tutorialized.com/tutorials/Flash/1
http://www.vectorkid.com/
http://www.cbtcafe.com/FLASH/
http://www.flashkit.com/
http://tutorials.flashguru.co.uk/
http://www.flashcircle.com/
http://www.flashdeveloper.nl/g_flash_Tutorials.html
http://www.sephiroth.it/tutorials/flashPHP/
http://www.flash-mx.com/flash/index.cfm
http://www.flashpro.nl/flas.html
http://www.developingwebs.net/flash/#MX
http://www.actionscripts.org/tutorials.shtml
http://www.flashmove.com/
http://tutorials.flashsitesweekly.com/flash/
http://www.stranger.per.sg/
Resources
Flash Sounds
http://flashkit.com/soundfx/
http://www.computerarts.co.uk/downlo...ashSounds1.asp
http://www.flashsound.com/
Flash Fonts
http://www.miniml.com/
http://www.fontsforflash.com/
www.orgdot.com/aliasfonts
http://www.vectorize.de/
http://www.superlooper.de/
http://www.fatorcaos.com.br/?l=trabalho/fontes http://www.alphaomegadigital.com/flash_fonts.asp

Oop

The ten main terms describing Object Oriented Programming:
1) Class -Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features).
2) Object -A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have
3) Instance -One can have an instance of a class or a particular object. The instance is the actual object created at runtime.
4) Method -An object's abilities. In language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods.
5) Message passing -The process by which an object sends data to another object or asks the other object to invoke a method. Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message
6) Inheritance -"Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever.
7) Abstraction -Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
8) Encapsulation -Encapsulation conceals the functional details of a class from objects that send messages to it.
9) Polymorphism -Polymorphism allows the programmer to treat derived class members just like their parent class' members.
10) Decoupling -Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction.
Above terms copied from wikipedia.org

Mystic Hunter

We reviewed the flash game Mystic Hunter today, check it out and play that game at http://hyperspatial.com/game_archive/html/mystichunter_game.html

Sunday, July 5, 2009

Tutorial

I am starting on my Hyper tutorial today. It is comprised of all things flash, focusing on as3 for sure. Work in progress but check up on it if you want to be powerful and rule the world with as3

Transparent .swf issue

I was creating a .swf file player for my website. The player is used to prevent the annoying "autoplay" that tend to be difficult to stop. Some flash games are setup so there is no easy way to prevent this, hence your page opens up and plays the game soundtrack right away. Sorry I need to control that, even setting javascript control for the flash to does not always work.

Anyway, the .swf file I created that plays .swf files when you click on the play button. The problem I had was that I set the player to this caused games controlled by the arrow keys to scroll the browser at the same time. That makes it impossible to play the game.

Moral = If you load a swf into another swf that is transparent you may have issues with browser scrolling

Wednesday, July 1, 2009

Not enough time

My daugher Siri, and her best friend


It seems like there is not enough time in the world today. Am I getting old, is time speeding up, like our perception of time?

I don't know, maybe when we were children the days just seemed longer because we had less stuff that we had to do and more stuff that we wanted to do.

I am trying to forge ahead, regardless of the lack of time or sleep for that matter. I am trying to create an online empire or web as they call it. It is difficult for a one man operation to accomplish the thing necessary to drive web traffic to my sites, getting the google bots to rank my site and such. SEO (Search Engine Optimization) is a very involved process that seems impossible for the individual to accomplish. Don't give up, I always say. So I continue my efforts:

This Blog
Hyperspatial.com
The Sensiri project
Personal Blogs
Forums

These websites are all in the works, and at various stages of construction. If you read this blog you definitely need to go to the sensiri site. I created a wonderful nature sounds player that you must have. I love it.

Optimizing all of these sites is a daunting task. According to my research, the professionals keep a team of people just to optimize one site, like a forum. I am asking for help, you can reach me via any of these websites. I am a programmer and inventive entrepreneur. I am trying to recruit people who want to make money on the Internet through advertisement. I know how to do it and I have the means I just need help from a few motivated individuals. My plan is to sell my software while making money advertising on various sites. I need content and good ideas.

Find me, you wont regret it!

Tuesday, June 30, 2009

Kaleidoscope

This is a .swf I created for the hyperspatial website.

Embarkation

As I embark on this journey I can't help but about the things that were.

Things that are depend on the things that were, otherwise there would be no now to behold. In the grand, quantum scheme of things our technologigal "now" exists because of the archaic past. More importantly it exists in its current state of exponential growth because of us, the human race. Out sheer numbers has fueled this techno revolution that we all have become a part of.

How many people did it take to design and build the first automobile?
How many people did it take to build the great pyramid.
How many people did it take to create the first microchip?

Those numbers may have been many but they hardly compare to how many of us contribute to the collection of files that comprises the internet.

Portal

This .swf is a work in progress. The portal is a drag and drop shortcut holder.

first post

here is my first post, ya hou