Copy link to clipboard
Copied
Hi!
I've finally decided to transfer the code of my component written in AS2 to AS3 and as expected there are many problems to solve! I think I overcome quite a few, but right now I'm stuck in the way to declare a component in AS3.
I've checked many forums, but never found exactly what the problem was. Must be very specific (and probably something stupid as well...).
So, first I created an .as file to declare the two parameters I need for my component.
package{
import flash.display.MovieClip;
public class Controller extends MovieClip{
[Inspectable(name="theContent", type=String, defaultValue="mcAnim")]
public var _theContent:MovieClip;
[Inspectable(name="theFrameRate", type=Number, defaultValue=12)]
public var _theFrameRate:Number;
}
}
Then in my .fla file, on the component, I do right-click > define component (might not be exactly these terms... I've got a French version).
In the textfield "Class", I wrote : "Controller"
In the other textfield, I wrote : "flash.display.MovieClip"
The Component as an instance on the stage. Inside this component, there's code that manages all the function needed for a controller (play and pause button, scrolling, etc.).
To make this all work together, I need to have access to these parameters I've declared in the .as file... but it returns me null of Nan.
Here's the beginning of my code (if it can help...)
import flash.events.Event;
import flash.events.MouseEvent;
var mcTimeStrip:MovieClip;
var mcHandel:MovieClip;
var mcPlayPause:MovieClip;
var btnPlay:MovieClip;
var btnPause:MovieClip;
var txt:Object;
var isPlaying:Boolean = true;
trace("content :" + _theContent); //returns null
trace("frame rate :" + _theFrameRate); //returns NaN
Thanks a lot!
Copy link to clipboard
Copied
You declared in a package, so you should create an object instance for that class and through that object you can able to access the variable inside the class.
Copy link to clipboard
Copied
Thank you for your quick answer!
I added the code you suggest and, sadly, the flash crashes now.
So here's the two lines I added, just under my other declarations of variables...
[...]
var btnPause:MovieClip;
var txt:Object;
var theController:Object = new Controller();
addChild(theController);
var isPlaying:Boolean = true;
trace("content :" + _theContent);
trace("frame rate :" + _theFrameRate);
Copy link to clipboard
Copied
Ok. So how I managed to "resolve" my problem. It's the easy/lazy solution.
I just declare my variables directly into the code and give them there their value. So it's no more a component.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more