Change name of document class - Flash CS Pro - actionscript-3

In document class, constructor, following line produces following error:
name = "hello world";
Error: Error #2078: The name property of a Timeline-placed object cannot be modified.
Is this doable or hackable?

I did some test, and it seems you can't.
"MainTimeline is the default class used for the document class. The document class is the display object which is added to the stage when the SWF movie is loaded. Underneath it is a normal class which extends MovieClip." (found here on SO)
Probably the implementation of this class blocks you to change its name. As you're not instantiating it, probably flash assign a name to this instance and doesn't want you to change it :)

Related

How to access variables within MovieClip (AS3)

I'm new in AS3 and I wanna ask how to access variables inside MovieClips by its name.
in AS2 usually, I use its instance name followed by .(name of variable)
for example...
I have a variable named baru inside a MovieClip named my_mc.
usually I use my_mc.baru to reveal the value of the variable.
Now, i want to know how to do it in AS3
Thank you.
In AS3 there's a few separate but related things you need to be aware of:
All display objects (including MovieClip) can have a name property.
var mc:MovieClip = new MovieClip();
mc.name = "myMC";
myContainer.addChild(mc);
You can find a child by its name using getChildByName() on its parent.
var myMC:MovieClip = myContainer.getChildByName("myMC");
MoveClip instances can have dynamic properties that point to children (or anything at all).
myContainer.myMC = myMC;
(Note that other display object types, such as Sprite, do not allow dynamic properties. Instead you need to create a custom class with class properties.)
When you create a display object in code (as shown above), neither the name or a property on the parent will be automatically created. You can do it manually as shown above.
When you place a symbol instance in the authoring tool and give it an "instance name", both the name and a property on the parent symbol will be assigned by that "instance name". In this case you are not allowed to change the name in code.
Note that in AS2 using createEmptyMovieClip or attachMovie would assign the _name and create a property on the parent, but there's no AS3 equivalent to these functions. This is where a lot of confusion can come in.
So as you can see the way this works is really not different than AS2, except that AS2 had functions that did several things for you (create and add the MovieClip, set the name and add a property on the parent). The problem with AS2 was that you couldn't re-parent an object after it was created, which was a big limitation. In AS3 you can freely move things around.
If you just like to write code inside the MovieClip but not a *.as,you have to add a TextField in the MovieClip by hand,set it's type to Dynamic,then type the variable string in it,then get it use: MovieClip.TextField.text and don't forget: TextField.alpha=0.
It is not a wise way.

Edit complex component in Flash IDE in one ActionScript class

I'm new to Adobe Flash. I'd like to create a button or component in Flash Professional using MovieClip and add label to it, and build my own button with special functions.
And i'd like use ActionScript to edit code. I faced a problem: i can not edit all code of my component (that cotains several ui-elements) in one AS3 class. I create empty document, add rectangle to it, then convert it to symbol. Next, i go to Advanced ActionScript 3.0 Settings of IDE, add path to folder where i put my Class.
Then add MyClass to Document class in that window.
But when i add new elements to the document, it doesn't appear in MyClass.as
Is it possible to edit complex component in Flash IDE in one ActionScript class ?
Sorry for a long explanation and for my poor english.
I create empty document, add rectangle to it, then convert it to
symbol.
Make sure symbol is type: MovieClip. Give it a name you prefer (no space is good idea). Further down (see Advanced section?) there is section called Linkage click "Export for ActionScript" and remember the name shown in Class box (you can edit it) and just click OK. No need for folder paths etc.
Lets assume the name used for Class is : myComponent
Now you can use it in your code. To make a document class open the Properties panel (ctrl+F3) and just type a name example Main (no extensions) and press enter and then save FLA and secondly also save the class code (it will ask for a file name so use as Main.as).
Now If you click that pencil icon in properties you will be editing class code (Main.as) for the FLA document and it knows your component if you reference it by code:
public var test_comp : myComponent = new myComponent (); here test_comp is just a quick reference name. Use your own preferred reference name.
You can edit the MovieClip of myComponent by right-clicking and choosing "edit" (not "edit Class"). Now you can add/draw different things and even convert them to Graphic or MovieClip and give them instance names. A MovieClip object is like a mini-stage so it has its own unique timeline and you can work exactly like if this was the main stage (but without actually affecting main stage).
If you add something to Component MC such as drawing a circle (as some button?) and convert that circle to MC or Graphic type with instance name circle1, in the code you access that as:
test_comp.circle1.alpha = 0.5; since test_comp is your code's reference name for that myComponent MC in the Library.
After testing the above example... now begin your own component.
Remember... If an object is inside the MC access it via it's instance name and if you need to addChild it from the Library instead then use its AS3 linkage name.

Issue with Document Class and Tutorial

So I've been following this tutorial on AS3 and Flash. Its been going well until, note I have tried to contact the writer of the tutorial and had no reply. Here's what it tells me to do;
Right-click PlayScreen in the library, select Properties, and check Export for ActionScript. This time, instead of accepting the default value, enter the name of your document class. Click OK.
So it pops up an error, first we’ll have to make a new document class, since no two different objects can share the same class. Cancel the Properties box.
Hit File > New and select ActionScript File. Enter the (by now familiar) code.
Save this in the Classes directory as DocumentClass.as. (There’ll be no confusing the purpose of this file!) Now, back in your FLA, change the document class to DocumentClass.
Check everything’s fine by clicking that pencil icon — if it’s all OK, that should bring up the AS file that you just created.
// So this bits all fine, its the next that i'm stuck with:
Now you can set the PlayScreen‘s class to AvoiderGame. So do so!
// So I go ahead into the properties and change the name but then it pops up with the same error as before: 'Please enter a unique class name that is not associated with other library symbols'
What does this mean!? How do I resolve this!?
Full tutorial here:Flash Tutorial
Its hard to tell what you are trying to accomplish without knowing what all the parts you are referring to actually do, which are objects in the library and which are classes, but maybe this can help:
First of all, document class in AS3 typically refers to the project's main set of code that initializes the app. This class can be called anything but is often called Main, and is entered in the property panel that is displayed when you click the projects main stage in the field called class.
Now, when linking a class to an object in the library, its a little different. In the library object's property panel, tick the box for Export for Actionscript, and put a unique name in the top box. This is what you reference in your code to call it, like new somethingOrOther() or using the pic below as an exaample, new Ball(). The second box is the base class, pathed to where it lives in your code base. This is the class you will write that actually controls the object you've linked the class to. Giving a linked object a base class and a unique identifier allows you to use the same base class for multiple linked objects.
Note that when you do this approach, Flash will warn you that there is no class associated with Ball and one will be created for you. Don't worry, this is normal behavior. If you set this up properly, your object will still be controlled by its base class.

How to reach button from contained in library from .as file

What I want to do is to add button as a child to a movie clip which is on stage. Get input in a text field and then save that input into String variable. This button should trigger this actions. Only problem I find is that I can't reach the button which is in library. I have set button AS linkage and I am trying to reach it trough that linkage.
This is the line of code which dosen't work:
enterName.addChild(nextButton);
Error I get is: Line 254 1061: Call to a possibly undefined method addChild through a reference with static type Class.
Since your button has a linkage, you should instantiate it, which means:
enterName.addChild(new nextButton());
An even cleaner version would be to have your linkage name with a first letter upper case (this is commonly how classes are named). And you could cast this instance as a DisplayObject to tell the compiler you know this class extends something you can add to a container:
enterName.addChild(new NextButton() as DisplayObject);

Actionscript 3: Adding a MovieClip (from library but not on stage) to a Sprite declared within a seperate class

What I am trying to do is add a MovieClip which I have created, but deleted from the actual stage itself, from a seperate class to a sprite which I declare in the document class.
The link between the main document class and the others works fine, as well as references to the stage, from the class in question.
It is only one line of the function which is giving me the error: Type was not found, or is not compile-time constant:SequenceA
I have already tried changing the settings for 'Export for Actionscript' in the library properties and still get the same message every time.
Pretty lost with this one so any help is appreciated. Cheers!
What have you set as the "Class" in your Export for ActionScript settings? It looks like you're trying to refer to an instance rather than the class itself. For example, mc is an instance of the MovieClip Class.
Assuming you've chosen the Class "SequenceA", you would do this instead:
var seqA:SequenceA = new SequenceA();
There's a little bit more detail about objects and classes here.