Saturday, November 24, 2012

Getting the window title in AS3

In AS3, you can easily access the name of the HTML page that the .swf is embedded in. To do this, you can use ExternalInterface. First, import the ExternalInterface library.

import flash.external.ExternalInterface;

Next, call the window location from JavaScript using the call function of ExternalInterface.

flash.external.ExternalInterface.call("window.location.href.toString");

This should work for most browsers; however, there have been reported problems using this method. If you experience difficulties with your browser, try wrapping the call in a JavaScript function.

flash.external.ExternalInterface.call("function(){ return window.location.href.toString();}")

In addition, you may want to find the path of the .swf file. Using the following code will get the path of the .swf:

var swfLocation = this.location.href;

One final note, the ExternalInterface calls only work when JavaScript is enabled on the page, so if it does not work, this may be the issue.

Happy Coding,
kieblera5

Thursday, November 8, 2012

How to Center a Page in CSS

Conflicting margins can be frustrating and confusing when constructing a stylesheet for your website. However, centering your website is a common practice to avoid margin conflicts. Centering your website also helps with readability and works pretty well with dynamic display of content.

The following tutorials will show you how to center your website using an ID selector in CSS.

THINGS YOU MIGHT NEED:
CSS basic knowledge
HTML file 
External CSS file

HTML File:

<body>
  <div id="page-wrap">
  all websites HTML here 
  </div>
</body>
External CSS File:

#page-wrap {     width: 800px;
     margin: 0 auto;
}
In other to avoid margin conflicts when resizing your window, it is very important to set the width of the selector to a giving pixel ( e.g 800px ) and also set the margin's initial value to 0 and auto to horizontally center the page.

Monday, March 1, 2010

Dictionary Shortener

Recently, I had to write a program that shortened the dictionary. What I mean by this is that using a full dictionary (over 237,000 words), I needed to weed out the words that were longer than eight letters and shorter than three letters. I needed a list of letters between three and eight letters for an upcoming game that happens to need a dictionary to check against.

Why do I bring this up? Well, my program takes advantage of fstream, a coder's good friend or enemy, depending on your understanding of it.

In my next posting, I will show you the finer points of using fstream, but for now, here is the code for the dictionary shortening program:



#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
 
int main()
{
    string word;
    ifstream infile;
    ofstream outfile;
    int count=0;
    infile.open("fulldictionary.txt");
    if(infile.fail())
    {
        cout<<"File could not be opened\n";
        system("PAUSE");
        return 0;
    }
    outfile.open("dictionary_short.txt");
    if(outfile.fail())
    {
        cout<<"File could not be opened\n";
        system("PAUSE");
        return 0;
    }
    for(int i=0;!infile.fail();i++)
    {
        getline(infile,word);
        if(word.length()>=3&&word.length()<=8)
        {
            count+=1;
            cout<<count<<": "<<word<<endl;
            outfile<<word<<endl;
        }
    }
    infile.close();
    outfile.close();
    cout<<"There were "<<count<<" words saved in dictionary_short.txt\n";
    system("PAUSE");
    return 0;
}



The above code assumes that you have a file called "fulldictionary.txt" in the project folder and will automatically create the output file. There's no need to make that one.

Friday, February 26, 2010

Creating Road In Unity Game Engine

Unity game engine is a great engine for developing game on PC, MAC, iPhone, and other platforms. However, I noticed that Unity does not have a road editor compared to Torque (game engine). One can use primitives to resolve this issue, but I prefer to use a 3d modeling tool. Thus, in this tutorial I will show you how to create roads using 3ds Max.

THINGS YOU MIGHT NEED:
a) A 3D modeling tool
b) Road Design/Map
c) Road Textures

1) Open 3ds Max, click CREATE and select SHAPES.
(click the picture to view in X-Large)

1b) Enter/Select all the necessary values and settings as desired. (Use the same values and setting to achieve similar results as this tutorial)


2) Create the desired road using the top view.


3) Select the Map Editor. (Shortcut: hit M on the keyboard to pop up the Map Editor)

 

3b) Click on the none button next to Diffuse. Double Click on Bitmap and select your road texture.

 

 4)  Make sure the desired material is selected.
4a) Select the "Assign Material to Selection" button in the Material editor to assign material
4b) Select the "Show Standard map in Viewport" to show material layout in your Viewport.
4c) Play Around with the Tiling Values to get the desired tiling.


5) Export as .FBX to Unity Game Engine.



~* By: Verse316 *~

Tuesday, January 5, 2010

Simple Console Program & Code Snippet Embeding.

Happy New Year! There will lots of code altering and editing on this blog this year. Thus, displaying code in code snippets will be very effective. How do you display or embed code snippets on your blog? There are several ways you can embed scripts or code on your blog. One of the easiest ways is to use Microsoft Live Writer. Once you have that installed you may need a plug-in that helps with formatting and highlighting.

Here is an example with a simple Console Program I made:
   1: #include <iostream>

   2: #include <iomanip>

   3: #include <string>

   4:  

   5: using namespace std;

   6:  

   7: int main()

   8: {

   9:     //** Declarations **    

  10:     double hourpay, twoweeks, month, year;

  11:     int ans, weeksWorked;

  12:     string name;

  13:     bool flag = false; 

  14:  

  15:     cout << "Welcome to the Budget Console" << endl;

  16:     cout << endl;

  17:     cout << "Please enter your name: ";

  18:     getline(cin, name);

  19:     system("cls");

  20:  

  21:     cout << name << ", How much do you earn per hour: ";

  22:     cin >> hourpay;

  23:     cout << endl;

  24:     cout << "How much do you work in a week: ";

  25:     cin >> weeksWorked;

  26:     cout << endl;

  27:     system("cls");

  28:  

  29:     //** Menu **

  30:     while (!flag)

  31:     {

  32:     cout << "\t Menu" << endl;

  33:     cout << "1) Calculate how much I earn in 2 weeks."<< endl;

  34:     cout << "2) Calculate how much I earn in a month."<< endl;

  35:     cout << "3) Calculate how much I earn in a year: ";

  36:     cin >> ans;

  37:     cout << endl;

  38:  

  39:     //** Calculation **

  40:      twoweeks = hourpay * weeksWorked;

  41:      month = twoweeks * 2;

  42:      year = (twoweeks * 2) * 12;

  43:  

  44:     //** Outputs **

  45:     if (ans == 1) {         

  46:           cout << "Your Two Weeks Pay: $" << twoweeks << ".00 " << endl;

  47:           flag = true;

  48:     }

  49:     else if (ans == 2) {        

  50:         cout << "Your a month Pay: $" << month << ".00 " << endl;

  51:         flag = true;

  52:     }

  53:     else if (ans == 3) {        

  54:         cout << "Your a month Pay: $" << year << ".00 " << endl;

  55:         flag = true;

  56:     }

  57:     else {

  58:       cout << "Invalid Selection" << endl;

  59:     }

  60:       }

  61:     system("pause");

  62:     return 0;

  63: }

Tuesday, December 22, 2009

Colored Output in C++ Console

Greetings!

I know I'm a day late, but there was a family emergency yesterday.

Our next topic is colored output in C++.
Have you ever wanted to get away from the boring white text on black background in console output? Well, I have an easy solution for you ;)

There is a wonderful function called SetConsoleTextAttribute. This function can set the output handle and the colors of the output (background and foreground).

It is a very easy function to use. Here is an example of the function:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 
BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);

First, the function keeps the output to the standard output (cout), then come the colors. There are three options for color in both foreground and background.

BACKGROUND_RED

BACKGROUND_GREEN

BACKGROUND_BLUE

FOREGROUND_RED

FOREGROUND_GREEN

FOREGROUND_BLUE


Use these as flags in the second part of the function's parameters, seperated by vertical lines (Shift+\).

If you are changing the background or foreground colors, you must also put:

FOREGROUND_INTENSITY
or
BACKGROUND_INTENSITY

depending on which color you are changing. The example function above changes the output to a white background (using all colors), with the "default" foreground (black). The color defaults to black when you do not choose it, if you use this function.

I used this function plenty to make a simulation program that included quizzes. I changed the colors of the incorrect or correct answers to visually stimulate the user.

One more thing: You need to include the windows.h header for this code to work. Use the following line in your code:


#include "windows.h"

I will upload test code when I can and link it to this post.


Until then,
Happy Coding!
kieblera5

Monday, December 14, 2009

Intro to HTML with notepad

It's very interesting how a notepad utility can serve as an editor for your website or blog.
Kiebler5 did a great job by describing the various uses of "namespace" in c++; However, this intro to HTML is intended to give beginners a feel of what programming looks like. (ps. HTML is not a programming laguage, it is a markup language)

HTML is a language for describing web pages.

* HTML stands for Hyper Text Markup Language
* A markup language is a set of markup tags
* HTML uses markup tags to describe web pages

I will show you how to create and run a simple html page. [click on images to enlarge]
Step. 1) Open notepad.
(Quick way to open notepad - hit Ctrl + R - and type "notepad" in the dialog box and hit "OK".)
Snapshot 1:
Step. 2) Type your own HTML code or copy this code into your notepad.
Screenshot 2:
Step. 3) Save the txt file as a .html format. This step is very important. This is because without the HTML extension your operating system may detect the file as a txt file.
In snapshot 3, I saved my html code as "simplePage.html".
Screenshot 3:
Step. 4) Locate your and run your html file.
Screenshot 4:
Next, Intro to CSS.
Until then,
Happy Coding
Verse316