Call the object inside the library by code - actionscript-3

I am a newbie. I'm on my project to make a interactive map. I do not want to make it with a many objects, but by the code. I want to ask you, is it possible to show the object in library by the code?
If so, how to call it?
Thank you.

Var instanceName = new LibraryName();
/* give it the properties you need */
stage.addChild(instanceName);
the instance name will be the name that you want it to take for your project
the library name is the name of the object in your library.
stage.addChild() is the function that allow you to add the object to the stage

You must give the object an AS Linkage, if you already done that, then you can refer that as a Class, like:
var clubPoint:CLUBOBJECT = new CLUBOBJECT();
The programming IDE will not recognize the class, but upon compiling and testing the file in Adobe Flash Pro CSx, CSx will automatically generate a new class for it, and thus you can use it.

Related

Access external SWF classes other than document class AS3?

I'm loading an external SWF as you normally would and I am handling the COMPLETE listener with:
var documentClass:Object;
function onComplete(loadEvent:Event)
{
documentClass = Object(loadEvent.currentTarget.content);
}
This works perfectly and I can access variables and functions from the document class of the external SWF. However not all the other classes in the SWF's library aren't instantiated in the document class. I would also like to access variables and functions in these other classes, and I am currently using, for example:
var documentClass:Object;
var classOne:Class;
function onComplete(loadEvent:Event)
{
documentClass = Object(loadEvent.currentTarget.content);
classOne = loadEvent.target.applicationDomain.getDefinition("ClassName") as Class;
}
This also works. However, there are multiple other classes in the library which I want to access and it is extremely tedious to go through each of them using this method. I was hoping I could use getQualifiedDefinitionNames() (I'm using Flash CC and player 11.3 so it is available) but when I trace it, it doesn't seem to be working.
There has to be an easier way to access the other classes which I don't know of. Can anyone help?
Thank you,
James

AS3 accessing variables from timeline from nested MovieClip(s)

EDIT: I figured this problem out on my own, and have included the answer below.
I have a variable in my main timeline called characterDismissed which is a Boolean. I also have a series of nested MovieClips (MovieClips within MovieClips) which look something like: Stage > Container > List > Buttons.
In the Buttons MovieObject at the bottom of the nest I'm trying to output characterDismissed's value just to see if it can see or modify it:
trace("characterDismissed is: " + characterDismissed);
This obviously doesn't work, and I understand why it doesn't work (because characterDismissed is not a variable in the Buttons ActionScript, but rather in the main timeline's ActionScript, so it has no concept of the characterDismissed variable yet.)
How would I go about making this variable accessible to the Buttons MovieClip in AS3? I've tried root.characterDismissed, parent.characterDismissed, this.parent.characterDismissed, even parent.parent.parent.characterDismissed, etc. These always give me some flavor of this error, however:
1119: Access of possibly undefined property characterDismissed through a reference with static type flash.display:DisplayObjectContainer.
I feel like I've been reading suggestions for handling this for days, but nothing is working, and with my understanding of AS3 being limited already, I don't have a proper grasp on the vocabulary to better research it past what I've already searched, or make sense of what typically ends up being a vague response on other forums, or for similar, but not-quite-right questions/answers.
I ended up figuring out the answer on my own, here's what I came up with:
I made a new ActionScript 3.0 Class file and named it GlobalVars (though, you can name it whatever you like.) and saved it into my project directory alongside my main .FLA file. In GlobalVars I made a test variable named testVar, set it to public, and then static.
My understanding for this is that public means anything can modify it, and static means that this variable will be the same value throughout your entire program. That looks like this:
public static var testVar:Number = 1234;
Then in both my Main project AS3, and the nested object's AS3 I added:
import GlobalVars;
This adds the class I made, and any functions or variables I configured within GlobalVariables to my Main AS3 script on the timeline.
Now, I have can access or change my variables in those AS3 scripts by simply prefixing the variable with the class name, like so:
GlobalVars.testVar += 20; // Add 20 to testVar.
Now, as long as I import GlobalVars into my script, I can access, and modify these variables from anywhere.
Hope this helps anybody else out there who found themselves lacking the vocabulary to properly articulate a search on this subject. I have attempted to include as many keywords in my explanation as possible to help people with similar search queries.

How to create a table dynamically in flash using actionscript 3.0

I am very new to flash and actionscript. I'd like to create a table dyanmically using actionscript code. Please help me.
Thanks in advace.
If you are referring to a dynamic array, then Action script has native support for dynamic random access containers in the form of their Array() object.
Simply instantiating a new Array object. Just keep in mind that you are responsible for managing the distribution of data in the container yourself. The object will not automatically compress itself if you simply remove an element in the middle of the array.
An example.
var numbers:Array = new Array();
numbers.Push("Five");
numbers.Push("Twelve");
numbers.Pop();
Here:
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7fdc.html
A full documentation on working with arrays and vectors.

Flash: pure actionscript project: ToolTipManager class not registered?

I have a pure ActionScript 3 project that I build using the open source command-line compiler. I'm trying to add tooltips to my controls using mx.managers.ToolTipManager.
The code compiles without issues, but when I try to add the tooltip I get the following exception:
No class registered for interface 'mx.managers::IToolTipManager2'
I experimented with trying to register a class against that interface manually, something like:
var toolTipManagerImpl:Object = ApplicationDomain.currentDomain.getDefinition('mx.managers::ToolTipManagerImpl');
Singleton.registerClass("mx.managers::IToolTipManager2", Class( toolTipManagerImpl ) );
...but that leaves me with a null ToolTipManager reference.
Any ideas what I have to do to use the ToolTipManager in this environment?
Thanks in advance.
The SWCs are not n the build path and, what is more important: it will most likely not work because the whole framework is missing, which the components rely on.

ActiveX in HTML

My requirement is to instantiate an object using new ActiveX() in html.
I have created a COM component SimpleActiveX using ATL. I have created the dll SimpleActiveX.dll for the same. In order to instantiate this component in html file I need to register the dll. So I registered the dll using the command regsvr32 %Path of dll%.
After doing so I am trying to create and instance of the component in html file as follows,
var req;
req = new ActiveX("SimpleActiveX.Hello"); //Assume Hello as a class.
req.Hi(); //Assume that Hi() is a member function of Hello.
By doing so I am unable to create the ActiveX object.
Html doesnt give any error too. I dont know whether I am doing anything wrong or am I missing anything.
Could anyone please tell me the proper steps to perform above operations.
How do I need to create the dll (Here in this case I have just build the ATL project in Visual Studio to generate the dll)?
What else do I need to do with the dll in case if I need to create an ActiveX object in html?
I had come across something called as <object> </object> tag in html where we mention the classid and attributes. I dont know whether I need to mention this in my html file or not.
Thanks for your help in advance.
To instantiate an ActiveX object in JavaScript, assuming the dll is correctly registered, you just have to use:
var req = new ActiveXObject("SimpleActiveX.Hello");
Unfortunately I don't know how to register a dll using Visual Studio.
Regarding the tag, it is used when you want to embed the object directly in your HTML code, so that it will be instantiated when the document loads, instead of using JavaScript.
For example:
<object id="myObject" classid="CLSID:2D360200-FFF5-11D1-8D03-00A0C959BC0A"></object>
Then you can access the COM object with
var myObject = document.getElementById("myObject").object