Today’s tutorial is a bit complex, but it solved a lot of issues faced by flash developer in AS3.
We will be touching on various subjects such as: -
Creating xml schema of your own.
Easier way of doing xml data retrieval AS3 style.
Loads the xml data into Listbox class.
NOTE : Listbox or List is a component in Flash so, it needs a separate import and special event Listener for that. You will get an error if you try to apply regular addEventListener like MouseEvent to it.
Where is those _root.VariableName in ActionScript 3.0?
Good question, well _root is still there, but in ActionScript 3 is usually replaced with stage.variable_name, stage.objectname or MovieClip(”name”) commands.
A neat way to make a reference to _root is as follow. E.g. calling a _root variable called score and update it to 10.
1
2
//Accessing _root variables and object names in Actionscript 3.0MovieClip("root").score += 10;
Today we are going to talk about the infamous Blue Screen of Death or known for short as BSOD. Microsoft named them as Stop errors designed to safeguard the system if the system encounters condition that compromises safe system operation. Ironically, I dont feel much of a pain when I was diagnosing BSOD for third party pcs however, I can get extremely desperate and frustrated if that BSOD happened to me.
This is an example on how one should do a hittest in ActionScript 3.0.
This is an example of plain simple flash mode, where MovieClipA(red) and MovieClipB(blue) - Red being draggable and blue square listens to the a HitTest condition.
Some criteria needed for this task :-
Two movieclips - Red and Blue
EventListener assigned to Red to have it drag and drop able.
EventListener for EnterFrame for Blue to constantly checks for HitTest condition
//Task to accomplish for HitTest//1. Two movieclips - Red and Blue (Given instance name MovieClipRed and MovieClipBlue//2. EventListener assigned to Red to have it drag and drop able.//3. EventListener for EnterFrame for Blue to constantly checks for HitTest condition//Task 1. is done in the stage itself.//Task 2. Place an Eventlistener on Red have it drag nad drop able.
MovieClipRed.addEventListener(MouseEvent.MOUSE_DOWN,startDragme);
MovieClipRed.addEventListener(MouseEvent.MOUSE_UP,stopDragme);
// Below is the trigger function for EventListener Task 2.function startDragme(event:Event):void{
MovieClipRed.startDrag(true);
StatusTxt.text = "Dragging Red";
}function stopDragme(event:Event):void{
MovieClipRed.stopDrag();
StatusTxt.text = "Dropping Red";
}
MovieClipBlue.addEventListener(Event.ENTER_FRAME,checkHitTest);
function checkHitTest(event:Event){if(MovieClipRed.hitTestObject(MovieClipBlue)){
StatusTxt.text = "Bingo - Blue has detected Red";
}}
Another big suprise for AS3 is the missing GetURL where we used to script it on buttons to open up url. However that was replaced in ActionScript 3.0. We use navigateToURL instead.
Just follow the example when scripting your button. Remember like in previous tutorials, you need to add an eventlistener to your button to attached a function to it.
1
2
3
4
5
6
this.YourButton.addEventListener(MouseEvent.CLICK,openURL);
function openURL(event:MouseEvent){var request:URLRequest = newURLRequest("http://www.isgoodstuff.com");
navigateToURL(request);
}