Sunday, April 14, 2013

Flash Builder / Action Script Progress

This weekend I spent some time working with Flash Builder and Action Script. I almost want to say that MUCH TIME WAS WASTED.... But, I can not really say that since I LEARNED MUCH. There are a couple things I want to pass along from this (until you get involved in this sort of programming, it may not make sense to you... but, if you DO try it out, you will appreciate these little kernels of wisdom.)

(1) Flash Builder has a little BUG - If you have ANY ERRORS in your Action Script .as file there is a chance that Flash Builder will NOT COMPILE your file and run it for you. IT MAY SIMPLY RUN THE LAST, ERROR-FREE COMPILATION. THIS CAN CAUSE YOU TO BELIEVE THAT YOU ARE TESTING YOUR NEW CODE/CORRECTIONS, WHEN IN FACT YOU ARE ONLY SEEING THE RESULTS OF PREVIOUS CODE. I wasted many hours, and ended up deleting my previous project (see prior blog post) because I was so confused by this. THE KEY to avoiding this is to BE AWARE that you may not be looking at the most recent compilation. You can fix this by addressing all of the little "error" icons that are listed down the side of your .as program prior to running it in debug mode.

(2) GLOBAL VARIABLES - I needed a global variable to keep track of the LOG-IN NAME of the student. This name is to be displayed at the top of the screen at all times. Since I am using a system that "swaps out scenes" as the student progresses, I need to have a global variable that remembers the student's name the entire time, and can be accessed by various objects on the stage so that the name can be displayed. Here was the solution: Within the top-level code (called the "application class") I defined the variable as shown in the 4th line of code here:


The variable is "usersName" and I set it to public/static so that it can be accessed throughout the entire Flash program. Above you can see it in the main (application) class "CWVirtualLabGenaric" which is going to be the actual name of the .swf file once it is compiled and saved to my website. (Here you can see me setting the value of "usersName" to the word "<login>" which will then be the first 'name' that appears on the screen when the students open up the program.)

Later in the file I use it in the LogIn Class, which is the "first scene" that is displayed on stage.


On the 9th line of code above you can see that I am setting namefield.text to equal the contents of CWVirtualLabGenaric.usersName. This is done WITHIN the logIn object. The key to this was that in order to access this variable from within another object I had to type in the name of the application class "CWVirtualLabGenaric" first. It took me a couple hours to figure this out, with help online.

Now I can use global variables to keep track of other things, such as student's scores/grades, throughout an entire activity. Very important indeed!

(3) I have put this all to work in a new file that marks the very start of my "Virtual Labs". In this file there are TWO SCENES, in which the first one is the student logging in. Once he logs in the first scene is deleted, the user name is updated, and then the second scene is displayed. This is a very important step as now I can simply repeat the process for as many scenes as I need in any given virtual lab/tutorial.

 


If you look at the code above you can see that _logIn is first placed on the "stage" and then that object is displayed and "played" until the user has logged in. Once he logs in a "logInComplete" event signal is sent, which tells the program to run the SwitchSceneHandler, which swaps out the _logIn scene for the next scene, which I actually call _sceneOne. Later I will actually program SceneOne to display some sort of information that the user can interact with. The process will be repeated, with various scenes, until the user has reached the end of the lesson/lab.

Time: 8 hours

No comments:

Post a Comment