Flash reference error: "Cannot create property __id0_ on MyMovieClip" - actionscript-3

I'm using Flash Builder as the main flash dev tool, and use Flash as assets creating tool.
Basically this works fine, but one day I made a 3D tween in Flash timeline, and then link the asset "MyMovieClip" with my actionscript code, like this:
package
{
import flash.display.MovieClip;
[Embed(source="somefile.swf", symbol="MyMovieClip")]
public class MyMovieClip extends MovieClip
{
public function MyMovieClip()
{
super();
}
}
}
Then this Error came up: "Error #1056: Cannot create property __id0_ on MyMovieClip".
I'm sure there's no "__id0_" in my fla file.
So I deleted the 3D tween animation layer and re-published the fla file, no Error encountered.
Any clues? Is that impossible to make a movieclip asset with 3D timeline animation?

Make your MyMovieClip class a dynamic class:
package
{
import flash.display.MovieClip;
[Embed(source="somefile.swf", symbol="MyMovieClip")]
public dynamic class MyMovieClip extends MovieClip
{
public function MyMovieClip()
{
super();
}
}
}
Otherwise, you may have a conflict with an instance on your timeline and property within the somefile.swf movie clip.

Related

Referencing Flash Professional Object in Flash Builder Actionscript

I am new to working with Flash Builder and Flash Professional. I have a movie clip called myplayer that I created in Flash Professional, and I am trying to code some ActionScript for it in Flash Builder that will change its position on the stage, but I keep getting the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at level_1()
Here's the code:
package
{
import flash.display.MovieClip;
public class level_1 extends MovieClip
{
public function level_1()
{
myplayer.x=650;
myplayer.y=350;
}
}
}
I know I am missing something, but I'm not sure what. Any advice?
There are two symbols here: level_1 and myplayer. Naming convention for classes usually start with a capital letter; so, I'm going to refer to these types as Level1 and MyPlayer.
So, here's the scene:
Level1 is your game level
MyPlayer instance is a child of Level1
The player of this level needs an instance name defined as myplayer.
myplayer is an instance of the MyPlayer class (ActionScript linkage).
Now from Flash Builder, our Level1 class may manipulate the child myplayer instance:
package {
import flash.display.MovieClip;
public class Level1 extends MovieClip {
public var myplayer:MyPlayer;
public function Level1() {
super();
myplayer.x = 650;
myplayer.y = 350;
}
}
}
Flash CS5 example source code with Level1 ActionScript class at: http://labs.jasonsturges.com/stack-overflow/examples/referencing-flash-professional-object-in-flash-builder/

Use Squiggly for Spell-checking on a TLFTextField

In CS6, I am trying to apply the Squiggly functionality to a TLFTextField in a movie clip. I've read the thread here: Using Squiggly in Flash CS5 and followed the setting recommendations, except my AS3 class is on the movieclip not the document. But there is no spell-checking and there is no compiler or run-time errors.
The movie clip that contains the TLF has a AS3 class called UserInput.
package {
import flash.display.MovieClip;
import fl.text.TLFTextField;
import flashx.textLayout.edit.EditManager;
import com.adobe.linguistics.spelling.SpellUIForTLF;
public class UserInput extends MovieClip {
// stage instances
public var userInput:TLFTextField;
public function UserInput() {
// add spell checking
userInput.textFlow.interactionManager = new EditManager();
SpellUIForTLF.enableSpelling(userInput.textFlow, "en_US");
}
}
}
I can enter text but there is no spell-checking. Am I missing something?
Thanks for your help.

ActionScript 3 Access Manually Added MovieClip Instance From A Class (not Document Class)

If I have an instance named "btnExit" which I added manually to the Main Timeline, I can refer to it from my Document Class simply by typing its name, eg.
package{
public class Engine extends MovieClip{
public function Engine(){
trace(btnExit.x);
}
}
}
But now I have an instance that is nested in another movieclip, and I want to access it from a class (not a Document Class).
Let's say I have "Menu" movieclip on my library.
Then I manually drag a "ButtonExit" button to the "Menu" movieclip timeline, I named the instance "btnExit", so "btnExit" is the child of "Menu" movieclip.
The "Menu" movieclip will be added dynamically by code to the main timeline.
Now I want to access the "btnExit" from "Menu" class file, so I write these codes.
The Document Class:
package{
public class Engine extends MovieClip{
public var menu:Menu;
public function Engine(){
menu = new Menu();
addChild(menu);
}
}
}
The Other Class:
package{
public class Menu extends MovieClip{
public function Menu(){
trace(btnExit.x);
}
}
}
But I got error #1009 (null object reference) for unable to access btnExit;
Can anybody help me, pleaseee?
Make sure that the instance of ButtonExit exists on every frame of the menu timeline and that it's instance named appropriately on every frame or write an if statement to only run your code if the Button is currently on the correct frame.
Every frame when the menu clip animates it's going to re instantiate everything on the frame, so if your second/third/fourth/etc frame doesn't have a clip named btnExit it's going to throw an error when the constructor is called for that frame.

Access the main timeline in a swc

I have some animation that was created in the main timeline in an FLA
I want to publish this as a SWC for importing via Flash Builder.
However- I can't find a way to do this. Any ideas?
The only workaround I know of so far is to copy all the frames into a movieclip symbol and then set that to "export for actionscript" This isn't ideal since then I need to reposition the entire animation so it's at 0,0- and since there are objects moving outside the bounds of the stage, etc. I'll have to do it by eye. Not ideal :\ so a better solution is much appreciated!
You could embed a .swf
package {
import flash.display.MovieClip;
import flash.display.Sprite;
public class Demo extends Sprite{
[Embed (source="test.swf")]
private var Test : Class
public function Demo() {
var test : MovieClip = new Test() as MovieClip;
addChild(test);
}
}
}

Access main stage from class definition file (as3)

I'd like to access the stage of the main timeline from w/i a class that extends a movieclip. Basically, I have a button in the main timeline that makes a HUD appear. The HUD is an extended MovieClip class. When people click on a button in the HUD, I'd like to remove the object from the stage of the main MovieClip.
#curro: I think your confusion may come from the fact that I am running this code from a class definition file. Clicking on a button w/i this object should remove it from the DisplayList of the MainTimeline. Here's the code from the class definition file:
package classes {
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Answers extends MovieClip {
public function Answers(){
listen();
}//constructor
//initiatlize variables
public var answersArray:Array = new Array();
private function listen():void {
submit_btn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){
answersArray.push(answer_txt.text);
e.currentTarget.parent.parent.stage.removeChild(this);
});//listen
}//listen
}//class Definition
}//package
trace(e.currentTarget.parent.parent) gets me the MainTimeline, and trace(e.currentTarget.parent.parent.stage) appears to return the main stage, but I cannot use removeChild w/o getting an error that I am trying to coerce the stage to be a DisplayObject (which it ought to be).
What's on the stage of the MainTimeline: A single button that, when clicked, adds an instance of the Answers class to the stage.
What's part of the Answers class that's not in the code?
I first created Answers as a MovieClip object in the main library. It has 3 parts:
a TextField named "answer_txt"
a "clear_btn" that clears the answer_txt
a "submit_btn" that submits the text of answer_txt and then removes the entire Answers object from the MainTimeline (at least, that's what I want it to do).
your class definition is really weird. Looks like a mixture of as2 and as3.
Try with this:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.*;
import fl.controls.Button;
public class Answers extends MovieClip
{
public var answersArray:Array = new Array();
public function Answers()
{
submit_btn.addEventListener(MouseEvent.CLICK, remove);
}
private function remove(e:MouseEvent)
{
answersArray.push(answer_txt.text);
this.parent.removeChild(this);
}
}
}
This works on my computer. Your code doesn't. I think it has something to do with the listen method. The class isn't still instatiated and you are making it work.
Hey, I can't make head or tail from the code. Where does submit_btn come from? Is it a property of the class? What about answer_txt?
You don't need to access e.currentTarget... to remove "this" simply:
this.parent.removeChild(this);
If you add that movieclip to the stage then you can access the stage from that class as simple as in the document class
stage
Otherwise you can't access stage from that class. But you can access it by sending the stage as argument when instantiate the class.