Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Transfer controller component from AS2 to AS3

Community Beginner ,
May 26, 2011 May 26, 2011

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!

TOPICS
ActionScript
636
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 26, 2011 May 26, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 27, 2011 May 27, 2011

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 30, 2011 May 30, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines