Wednesday 18 September 2013

TypeError: Error #1034: Type Coercion failed: cannot convert the_game@24d270b1 to flash.display.MovieClip

there is nothing wrong with your code.  So since the error is indicating you are trying to treat a MovieClip as if it is a SimpleButton or any , somewhere in your design you have done something to attempt to coerce that MovieClip into being a Button (or possibly vice versa if it is actually a Button).  Check the properties panel and elsewhere to see if you have selected something that would be trying to make that button a different type of object than what it is.


Try creating a new movieclip and assign it that name (removing it from the other) and see if you still get the error.  If that works, then I recommend just creating a new movieclip and replacing it for the current one that is giving you the problem.

1180 error:Call to a possibly undefined method addFrameScript in as3

Sol 1 :-

Let me get this straight: you have set a Document Class in fla properties and are writing code directly in fla as well?
If this is the case, solution is simple: either write your code only in external .as files and not fla or do not use Document Class if you wish continue writing code on the Timeline. The error code you get states that you have code on your Timeline which behaves like a MovieClip, while your Document Class extends Sprite and therefore is not aware of method called addFrameScript (this method is called while compiling code that is on the Timeline into SWF file).
In short, I'd adviced you to change


public class SetTimeoutExample extends Sprite {
to
public class SetTimeoutExample extends MovieClip {

and move all your fla code to Document Class



Sol 2 :-

I solved the problem and now I'm successfully using an external AS class while implementing some other function on the TimeLine:

The problem can be solved just following this simple "rule":

if you want to JUST load everything from the external CLASS, you have to "link" the .fla file to the .as ("Document Class"):

the timeline use the addFrameScript function

if you want to USE something from the class, while doing something else on the timeline, you JUST HAVE TO PUT a similar line on the TimeLine:

var myClassObject:myClass = new myClass();
this.addChild(myClassObject);

Tuesday 17 September 2013

MVC Design Pattern in AS3

“Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC,

The model represents the information (the data) of the application and the business rules used to manipulate the data;
The view corresponds to elements of the user interface such as text, checkbox items, and so forth;
The controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements.”

The MVC Design Pattern
Creates a separation of Class roles
Adds a clear and logical communication structure
Increases flexibility in larger applications
Model
    Handles data storage and retrieval (eg. Store character x position)
View
    Handles the display/communication (eg. Position character on stage)
Controller
    Handles most the of the application logic (eg. Get current x position)

MVC – basic structure
Each model can have multiple views
Each view has at least one matching controller
Creates a separation between form, content and action
The model becomes the base of the application




Sample Game:-

Aim:-

A Square with randomly changed color when button was pressed

Architecture:-