-
1. Re: Jesus - where has 'onClipEvent(load)' gone???
clbeech May 17, 2009 1:25 PM (in response to Ziggizag)lol - ok calm down and don't panic - AS3 is more strict, however infinitely more powerful. it's become fairly well known that the use of 'on' handlers is not a 'best practice' and even in AS2, using class files to construct your code is an advantage. AS3 is based on more sophisticated models that allow for more advanced control - it's different, and takes some getting use to but ultimately much much better. so mainly you need to understand that most instances are now 'class' based, and actions that occur use the 'event' model - both of which are greatly helpful.
when you make a MC in the lib - consider that it is a class. each symbol can then be defined within a class file, this is where you can instantiate properties of the object and create methods that are specific to that particular class. you now instatiate display objects using a constructor operation and bring them to the stage using the Display Object methods - like addChild().
so to make a class for an MC in your lib - open a new 'actionscript' file - then you will define the class like so:
package {
import flash.display.MovieClip;
public class myMC extends MovieClip {
public function myMC():void {
}
}
}
the 'constructor' is the function 'myMC' - which is also the same name as the class and the MC in the lib. save the file within the same directory as the main fla file you are working on. now, to add a property to the class like 'id' create a new property of the object like this:
package {
import flash.display.MovieClip;
public class myMC extends MovieClip {
public var id:int = 1;
public function myMC():void {
}
}
}
now back in the fla file, right click the symbol in the lib - select properties, select 'export for actionscript' and the name of the sybmol will appear in the field - to the right of the field click on the checkmark - if you have set up the class right it will tell you that a class definition has been found for the instance and your good to go.
then to instantiate a new instance of the symbol on the stage you use:
var theMC:myMC = new myMC();
addChild(theMC);
any further references to the instance will now be made via the property name that was assigned to the instance (ie. theMC) so to position the clip for example use:
theMC.x = 100;
so - just a quick run down on the process - there is far more to know and understand. keep reading the docs and you'll get there eventually
-
2. Re: This is the solution
Ziggizag May 17, 2009 2:04 PM (in response to Ziggizag)Yeap, I've got it, though it was tricky:
1) Create a plain text document, name it hideOnLoad.as, paste the following script inside and save somewhere on your hard disk:
package{
import flash.display.MovieClip;
import flash.events.*;
public class hideOnLoad extends MovieClip{
public function hideOnLoad(){
this.addEventListener(Event.ADDED, hideMe);
}
private function hideMe(ev:Event):void{
this.visible = false;
}
}
}2) Open "Publish" settings, select ActionScript version 3 and then press "Settings" button. In the pop-up window add a "class path" - select the folder you saved your 'hideOnLoad.as' file in. Leave all the other settings default. Close this window and close the publish settings window.
3) Select a movie clip symbol in the library, open its properties window. Check "Export for ActionScript" and "Export in first frame". In the "Class" filed type "hideOnLoad" and click the green checkmark on the right side. You'll see a popup message confirming a class was found within a given classpath.
Now, when you publish the movie given movieClip instance is not visible while instanced.
Ough - that was nasty... I posted this message for all the loosers like myself :-)
Rgs,
Ziggi
-
3. Re: But there is another problem !!!
Ziggizag May 17, 2009 2:32 PM (in response to Ziggizag)In case you would like to associate 'hideOnLoad' extension class to more than one movieClip symbol in the library you need to type 'hideOnLoad' in the 'base Class' field while typing a unique name in "Class" filed of a movieClip properties.
-
4. Re: But there is another problem !!!
Muzak May 17, 2009 3:18 PM (in response to Ziggizag)In case you would like to associate 'hideOnLoad' extension class to more than one movieClip symbol in the library you need to type 'hideOnLoad' in the 'base Class' field while typing a unique name in "Class" filed of a movieClip properties.
There's no need for that.
Allthough it depends on what it is you're trying to do, because normally you wouldn't associate a class with multiple MovieClip symbols.
If you want multiple instances of the Class, you just drag another MovieClip from the Library to the stage (or instantiate one through ActionScript).
If you're looking to extend the class, it is ok to leave flash.display.MovieClip as the base class and fill in the name of the new class in the "Class name" field.
In the new class (.as file) have it extend the "other class" (HideOnLoad).
package { public class NewClass extends HideOnLoad { } }Note it's a good habit to have classes start with an uppercase character (HideOnLoad instead of hideOnLoad).

