Tag Archives: Members

C#: Day 3

Yesterday, finishing lesson 13 through 17, a big piece of the puzzle is where it should be. Though I did pause, rewind and replay as well as use Notepad extensively while also commenting the code excessively. Later, a Eureka moment had everything become easier to grasp. Now, the terminology is becoming part of my vocabulary and the syntax is becoming increasingly natural. I love the fluidity of the Microsoft Visual Studio Express 2013 IDE with its Code Snippets and its IntelliSense, which when you get used to them, will have you writing code efficiently. I like Visual C#.

While progressing through the series, there is less and less familiarities with my previous knowledge of the Amiga ARexx and Assembly language programming. The Amiga Workbench .library files are now essentially Assemblies in .dll files with the .NET Framework, which is a library of Classes that you reference. In a sense (but not exactly), the keyword is now ‘Using’ Instead of ‘Include’. There, you have Namespaces with Classes and their Members, the Methods and Properties. The concept of References are familiar too and now Memory Allocation is done by the .NET Framework Runtime.

So, Microsoft .NET and the Common Language Runtime (CLR) have been introduced and I am happy, as there is great benefit from it. I did like being as close to the hardware as the Assembly language had me be, it being a low-level programming language, with the Data registers, Address registers, Stack pointers and Program counter of the Motorola 68000 architecture. The thought processes were close to the behavior of the hardware, while now, its high-level programming languages that are instead akin to natural language. It does have its advantages of course, although I still prefer the former.

Familiarity was closest to my previous knowledge of ActionScript right from the beginning. I recognize Properties, Data types, Statements, Arguments et cetera from ActionScript, as well as the Syntax being somewhat similar. ActionScript 3.0 is an Object Oriented Programming (OOB) language as is C#.

Thus far, I am not able to do any programming of significance with what I have. Rather, I am still getting the know-how to be able to. We’ll see where I’m at after Day 4.

This is code I wrote while I was learning ActionScript 3.0 with lynda.com Flash CS3 for Designers. It is easy to comprehend it having gone through this series and vice versa:

// Output
// trace("Hello World");
// Cat object, claw attribute equals sharp
Cat.claw = "sharp";
// Listen to the event of woman shout and then make cat do
Woman.addEventListener(Event.Shout, makecatdo);
// Function make cat do
function = makecatdo() {
	// Cat object, jump method
// A variable is a container for information, : and then type of variable (strict type)
var h:String = "Hello World";
var weather:String = "It's cold";
// A function is used to control when we want to do certain things
function traceit(e:Event):void {
	// String concatenation
	trace(weather + " in December");
// CamelCase myArcadeButton, listen to an event, mouse click, traceit or textit
myArcadeButton.addEventListener(MouseEvent.CLICK, textits)
// Set text property of myText
function textits(e:Event) {
//	outText.text = "My dynamic text or trace button";
	// Set input text equal to outText
	outText.text = inText.text;
// Seamless Roll Over and Roll Out
function rollover(e:Event) {
	// In and out labels should be the frame after stop action frame to get smooth transitions
myBtn.addEventListener(MouseEvent.MOUSE_OVER, rollover);
function rollout(e:Event) {
myBtn.addEventListener(MouseEvent.MOUSE_OUT, rollout);
// Set masker as myImage mask, use cash as bitmap on both to get shape soften fill edges (alpha)
myImage.mask = themask;
// Mask to behave as a button so that we can add a mouse event to it
themask.buttonMode = true;
themask.addEventListener(MouseEvent.MOUSE_DOWN, drag);
function drag(e:Event) {
	// Enable drag functionality
themask.addEventListener(MouseEvent.MOUSE_UP, nodrag);
function nodrag(e:Event) {
	// Disable drag functionality
// So that it doesn't continue draging if mouse up outside mask
themask.addEventListener(MouseEvent.MOUSE_OUT, nodrag);
// UILoader component function to change source (load image)
function loadit(e:Event) {
	myLoader.source = "C:/image.jpg";
loaditBtn.addEventListener(MouseEvent.CLICK, loadit);
// Create object textLoader with all the properties and methods of the URLLoader class
var loader:URLLoader = new URLLoader();
// Create object requester
var requester:URLRequest = new URLRequest("C:/text.txt");
// Load the requester
// When an event, loader.load(), is done, show text
loader.addEventListener(Event.COMPLETE, showtext);
// The show text function
function showtext(e:Event) {
	// myText text is going to be the data that the loader has loaded from requester
	// Can also be dynText.htmlText so that it can parse html tags
	dynText.text = (loader.data);
	// Properties
	dynText.background = true;
	dynText.backgroundColor = 0x000000;
	dynText.border = true;
	// Hexadecimal color starts with 0x instead of html #
	dynText.borderColor = 0xff6600;
// Clear loaded image
clearitBtn.addEventListener(MouseEvent.CLICK, clearit);
function clearit(e:Event) {
		myLoader.source = null;
/* An instance of the array class, not a new empty array, but a predefined array
   Array data is defined withing brackets, separated by commas
   Arrays are storage for multiple variables, entries are numbers starting from 0 as the first */
var myArray:Array = ["C:/image0.jpg","C:/image1.jpg","C:/image2.jpg","C:/image3.jpg","C:/image4.jpg","C:/image5.jpg","C:/image6.jpg","C:/image7.jpg"];
// The caption array for the images description (desc)
var descArray:Array = ["First image","Second image","Third image","Fourth image","Fifth image","Sixth image","Seventh image","Eighth image"];
// Gallery
tnBtn1.addEventListener(MouseEvent.CLICK, img1);
function img1(e:Event) {
	// Load first image from first variable in array, access entries in array within brackets
	galleryloader.source = myArray[0];
	caption.text = descArray[0];
tnBtn2.addEventListener(MouseEvent.CLICK, img2);
function img2(e:Event) {
	galleryloader.source = myArray[1];
	caption.text = descArray[1];
tnBtn3.addEventListener(MouseEvent.CLICK, img3);
function img3(e:Event) {
	galleryloader.source = myArray[2];
	caption.text = descArray[2];
tnBtn4.addEventListener(MouseEvent.CLICK, img4);
function img4(e:Event) {
	galleryloader.source = myArray[3];
	caption.text = descArray[3];
tnBtn5.addEventListener(MouseEvent.CLICK, img5);
function img5(e:Event) {
	galleryloader.source = myArray[4];
	caption.text = descArray[4];
tnBtn6.addEventListener(MouseEvent.CLICK, img6);
function img6(e:Event) {
	galleryloader.source = myArray[5];
	caption.text = descArray[5];
tnBtn7.addEventListener(MouseEvent.CLICK, img7);
function img7(e:Event) {
	galleryloader.source = myArray[6];
	caption.text = descArray[6];
tnBtn8.addEventListener(MouseEvent.CLICK, img8);
function img8(e:Event) {
	galleryloader.source = myArray[7];
	caption.text = descArray[7];
// Music loop on off toggle
myMusic.myStop.addEventListener(MouseEvent.CLICK, stopmusic);
function stopmusic(e:Event) {
/* ActionScript 2.0
myMusic.myPlay.addEventListener(MouseEvent.CLICK, playmusic);
function playmusic(e:Event) {
/* Variables */
// Whole number, integer, positive or negative
var score:int = 15;
// Whole number, integer, positive
var score:uint = 15;
// Whole number, integer, positive, negative and decimal
var score:Number = 15;
/* Functions */
// Create function addNumbers with parameters num1, num2 with datatypes Number (Strict typing) and the function will also return a number :Number
function addNumbers(num1:Number, num2:Number):Number {
	// Return the sum of num1 and num2
	return num1 + num2;
// Run the above function (and trace result)
/* Events */
// Function will recieve value information to parameter "event" with datatype MouseEvent, return void (event handler function)
function buttonClicked(event:MouseEvent):void {
	trace("Button Clicked");
/* Event Listeners */
// Connect object my_btn with an event, in this case, a mouse event of click, and further connect it to an event handler function, buttonClicked above
// my_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
/* Arrays */
// Create variable my_ary and make it an array datatype
// Square brackets, shorthand notation, can have multiple dataypes, separate with commas
var my_ary:Array = [5, "David", true];
// Each item in an array has an index number which starts at 0 for the first item
/* Dynamic text */
// Create an instance of the URLLoader class, first part of creating a dynamic text loader, the object that will hold the external text once loaded
var textLoader:URLLoader = new URLLoader();
// Create URL request, second part of creating a dynamic text loader
var textReq:URLRequest = new URLRequest("as3.html");
// External CSS
var cssLoader:URLLoader = new URLLoader();
var cssReq:URLRequest = new URLRequest("as3.css");
// Make an object with the StyleSheet class
var style:StyleSheet = new StyleSheet();
// Define tag a style, object datatype and class is a dynamic class we can create custom properties on any instance of the object class (object shorthand notation {}) setStyle method of the StyleSheet class, the style of a is in an object with dynamic property color, colon to specify value, which is a string
// style.setStyle("a", {color:"#CC0000"});
// Load external text
// Listen to when text is finished loading
textLoader.addEventListener(Event.COMPLETE, textLoaded);
// Function for the event when text had finished loading
function textLoaded(event:Event):void {
	// End instance names with _txt and _btn for code hints, text property .htmlText, the data that is loaded in from the external text .data, .text for ascii
//	external_txt.htmlText = textLoader.data;
	// Apply internal stylesheet
//	external_txt.styleSheet = style;
	// External style sheet
	cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
function cssLoaded(event:Event):void {
	// Read the text as CSS
	external_txt.htmlText = textLoader.data;
	external_txt.styleSheet = style;