IAT167-Arrays2 Example.docx

52 views1 pages
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var myNumbers:Array = new Array ();
myNumbers = ["a", "b", "c"];
trace(myNumbers);
trace("the length of my array is" + myNumbers.length);
var lastitem:String = myNumbers.pop();
trace(myNumbers);
myNumbers.push("word");
trace(myNumbers);
//Event
//1) Import "Event class" package
//2) Add event listener to an object with addEventListener() args inside
//3) Event handler on MouseClick(); occurs with even happens; accpets event
object-continuous info (x, y)
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
trace("You clicked on the stage");
trace(event);
}
}
}
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Grade+

Unlimited access to all notes and study guides.

Grade+All Inclusive
$10 USD/m
You will be charged $120 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.