ActionScript 3.0 :: Instantiating A Class (mc) At Runtime?
Nov 16, 2010Code:
var myOnStageClip:MovieClip = this.fileInstanceMC;
var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));
[code].....
Code:
var myOnStageClip:MovieClip = this.fileInstanceMC;
var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));
[code].....
I am having a problem instantiating a Character class inside of a game class.I am working on converting URL...l these tutorials to A.S. 2.0.[code]
View 2 RepliesI am trying to use AMF PHP to pass variables to a flash file, thus far I cannot see anything wrong with my code, but I have very little experience with creating classes, so here it goes, here is my code,
index.php:
<?php
include "amfphp/services/flashMe.php";
$session = true;
[Code].....
Flash is looking for the flashMe class and the push method within that class, but I keep getting null variables in my flash file when I run it
My Class B imports Class A.Class A is associated to an FLA. This FLA has a moviclip (MC) in its library.Now I need to dynamically instantiate that movieclip MC from Class B. How can I do that??
View 9 RepliesWhen I set the following class as my document class it works (draws a rectangle) but when I don't set it as my document class and instead instantiate it using var myRec:simple_shape = new simple_shape(); in first frame of my timeline nothing happens no rectangle and no error either). why and how I can get it to work without setting it as my document class?
[Code]...
I asked yesterday how to call a function from an XML file, and I figured out how to make that work using the string-to-function call.so in my XML file I have <ITEM CALLBACK="ContactsList">View All</ITEM>, and my TextMenu class parses the XML file and creates my navigatable text menu instance. When enterMenu():String is called, it looks to see if the CALLBACK attribute has a value, and if so it returns it as a String.so..
var callbackFnc:String = textMenu.enterMenu();
if(callbackFnc != null)
{
[code].....
I am loading one swf into another using the Loader class, but when the child swf finishes loading and is added to the display list, its Document Class is not instantiated. I have a few trace statements that should execute when the object is created, but nothing is happening when loaded into the parent SWF. When I compile the child SWF on its own, the Document Class runs as expected.
So I'm wondering... how do I associate a child SWF's Document Class with Loader.content?
[Code]...
Is there a way I can load a swf file but not automatically instantiate it's DocumentClass? Instead I want to do something like the following:
protected function mainLoaded(e:Event = null):void {
trace('mainLoaded');
var main:* = this.mainLoad.createClassByName('Main');
trace(main);
}
Where mainLoad is an instance of CasaLib's SwfLoad and createClassByName is the equivalent to
loaderInfo.applicationDomain.getDefinition();
The thing is that when my swf finishes loading I can see it is created, because of some trace calls, although its obviously not added to the display list.
Here is the code:
ActionScript Code:
private class someFunction(classRef:Class):void
{
try
{
var instance:Object = new classRef();
[Code]...
Can I perform the check without instantiating?
I've got a confusing situation which wont seem to fix itself basically I have my main class, my iContent class (which will hold each page and have functions for all pages), and my individual pages.
The homepage is instantiated by calling the iContentClass.goHome method in the main document class. The home page contains a button to go on to the next page. This button references the goColourBrowserPage function within the iContentClass, which removes the child (being the home page) and attempts to add a child (colourBrowserPage).
For some reason this doesnt work! It doesnt seem to add the child and wont let me remove the child of the home page! I've been sitting here for 3 hours trying to work it but to no avail!
[Code]...
Is there a way to declare and instantiate an array using constants as indexes? I want to do something like:
public var arr:Array = new Array([ CONSTANT_A : "helloWorld", CONSTANT_B : "helloGoodbye" ]);
In php one could do:
$arr = array(CONSTANT_A => "foo", CONSTANT_B => "bar");
I'm making an app with pages set out as classes which extend the MovieClip class.
What I've got are back buttons and different pages which go to the same page, however... If I end up going out of a page and back into a page (specifically one with drawn squares and dynamic text boxes called from a web service), it seems to have kept all of the original information.
So far I've tried killing all of the children with a while loop targeting the index and also using weak event listeners - neither is working!
If I only instantiate a class once should I make its vars static? I understand how this is of benefit if I make multiple classes, clearly you use less memory as it creates a reference to the same place for each class. Are there any other benefits for creating static vars or functions ?
For example I have my class 'MainMenu' which I create once (might even be my document class). In it I create a
Code:
private var someHolderForStuff:Sprite = new Sprite();
Should I rather create
Code:
private static var someHolderForStuff:Sprite = new Sprite();
I have a MovieClip symbol that has 2 frames (for now). Depending on how it was initilialized, I want it to gotoAndStop at either frame or 2.Inside my class definition (Animal.as), I have written this as my constructor:
var type:String;
public function Animal(t:String = "") {
type = t;
[code]....
Let's say I have a defined ClassA. ClassB extends ClassA and there's a Movie Clip instance on the stage linked to ClassB. How would ClassC access the properties and methods of ClassB without extending ClassB or creating a new instance of ClassB? The way I'm currently doing it is by referencing the stage instance linked to ClassB and then using the dot syntax to access ClassB instance variables, and this works only if the the accessed variables are public or internal, depending on what package ClassC is part of. I would like to know if there's a better, cleaner way to accomplish this.
[Code]....
I'm having this problem: I have an external fla (Dawn.as) and I want to instantiate the class from the external file into the main swf timeline, but when I try doing that I get an error:
ActionScript Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Code::Chapter/initialise()
[code].....
've tried calling constructor class from my main.fla, and it just doesn't work. The error when I try to instantiate the constructor is that it needs an argument... and since the class extends a Sprite.
PHP Code:
public functionportGal():void {
this._images = new Array();
[code].....
I am trying to set up a script that will generate a matrix repeating the same symbol X by Y times. For example, b(3,2); should generate...
OOO
OOO
...and after many days of being tested by this problem I have narrowed the location of my problem down to what can be seen up in the following.
Code:
for (a=0; a<4; a++){
for (b=0; b<4; b++){
var z:Number = ((a*4)+b);
_root.attachMovie("Light", ("L" + z), _root.getNextHightestDepth(), {_x:(a*45), _y:(b*45)});
}
}
For some reason, that loop will only attach one copy of my "Light" movie. I cannot seem to figure out why more are not added. I am putting that code on the first frame of my movie. There is nothing else in my project yet.
I have compared my array to [URL]
I have a symbol named picHolder. In symbol properties under linkage, I chose "Export for ActionScript" and "Export in frame 1" and gave it a class name of picHolder.Normally, to instantiate a new instance, I'd say:
Code:
var tempPic:picHolder = new picHolder();
and I'd go about my way.
[code].....
I'm not really asking how. What I'm asking is, is it possible? And I ask because I thought it was not - certainly it didn't work in AS2 - and yet that's what I appear to have done. Am I going crazy? Structure: A SWF (#1) with a class NewActivity that extends class AActivity. Another SWF (#2) with a shared library of code in it, including AActivity. A third SWF (#3) which loads the library followed by SWF#1. Here's what happened: I didn't expect AActivity to be able to be shared. I mean, it should be compiled no matter what in SWF#1, as SWF#1 includes a class that extends AActivity. I had added some properties to the AActivity class, ran the project, and when SWF#3 tried to set those properties I was told they couldn't be applied. "Of course", I said, "I need to recompile SWF#1, because the code is now out of date. The version of the class there doesn't include these new properties.".
However, that didn't work. I got the same problem. Maybe, I thought, there's a definition conflict between SWF#1 and the library, so I removed the AActivity class from the shared library in SWF#2 for the time being. Only SWF#1 uses it, and it should already be compiled into SWF#1 as, like I said, it is extended by another class there. But when I ran the project, I was then told that the AActivity class could not be found at all! Looking at SWF#1 in a decompiler, there is in fact no mention of AActivity (I had up to this point assumed it was implied). So this left just one option: I needed to recompile the library in the first place, not SWF#1. I added AActivity back to the library, recompiled, and it worked.
To check I wasn't going crazy: I added a test property to the AActivity class and recompiled the library. The containing project - SWF#3 - then set this property on SWF#1, which had NOT been recompiled, and then read it back out. No errors. I should point out that the getting/setting of this property is done through an IActivity interface - AActivity is not being accidentally compiled into the main project (SWF#3), and the decompiler indicates this also. Am I going nuts? I really didn't think having a runtime shared super class was possible in any way. If it is, that opens up a whole new world of awesome, even though I've created this project on the basis of that being impossible.
Getting this error when instantiating this class. It's set up in my FLA as the document class:
ReferenceError: Error #1056: Cannot create property tab0 on
classes.tagwidget.TagWidget.
at classes.tagwidget::TagWidget/::addTabs()
at classes.tagwidget::TagWidget$iinit()
How to get CSS class name of any UI Component at runtime?
View 1 RepliesI know how to set individual style names to a UI component but what is the way to set set the CSS class itself?
View 1 RepliesIs there a way to runtime-type a class with tokens, like the Vector class, or it is exclusive to FlashPlayer and Adobe Team?
[Code]...
I have a MovieClip with multiple child MovieClips. I would like to add a class to each child MovieClip. Unfortunately, I can't just create the class and mc.addChild(class) because classes aren't display objects.
View 3 RepliesI'd like to be able to generate a class that inherits from BitmapData at runtime. Is this possible in Actionscript 3? If so, what is the syntax?
View 3 RepliesIn Actionscript 3, if I'm given a Class object, is there any way to determine if that class extends from another given class? I don't want to instantiate the class to check it with the is keyword, though.
[Code]...
I have a class which takes in another class as one of its parameters, and creates instances of it according to certain rules.In the past, I've had no problem with passing classes from the library to that class, which obligingly does its magic.In this case, however, I'm dynamically loading an image at runtime. I'm trying to wrap that image in a MovieClip, and somehow pass that clip *as a class*, to the one that creates multiple instances.Is this possible? I thought I'd cracked it with something like:
Code:
theMovieClip.addChild(thePicture);
var apples:Class = Class(getDefinitionByName(getQualifiedClassName(theMovieClip)))
[code].....
I would like to choose between two classes that initiate a load of 3d stuff.
along the lines of:
Code:
if (LOW_QUAL)
{ var galaxy:Galaxy_LoQual = new Galaxy_LoQual (gal, light ) }
else
[Code].....
Is there a way in AS 3 to trace what embedded fonts are available to your class at runtime.
View 1 Replies