Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Instantiate Class From A Different Movie



Hi,

I have scripting access to a movie that I'm loading in. Is it possible to instantiate a class from this movie from the movie doing the loading?

I can get code to compile in the movie doing the loading by using the 'intrinsic' keyword on a dummy class definition but when I try and instantiate the class using the real definition of it in the external movie at runtime it says that the class doesn't exist.

Any ideas?

Cheers, CN.



FlashKit > Flash Help > Flash ActionScript
Posted on: 08-08-2007, 06:44 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

[F8] How Can I Instantiate Class With Var?
My problem is instantiating a class. The class should start after a succesful load to a webservice. However I cannot figure out how to instantiate my class.

My idea was to create an array on the keyframe, then make an element of that array my class.

*NOTE; I have already done the load functions for the web service. It does load properly, and I don't get any error messages.


Code:
import mx.services.WebService;
import classes.*;
//
var manage_ws:WebService = new WebService ([link]);
//
var classAr = new Array(0);
//
load_list = manage_ws.GetSlidesForSlideType (localID, sID[1]);
//
load_list.onLoad = function (list) {
var className = list[0].SwfFileName.split (".swf");
var cName = className[0];
//
startClass (cName, list);
};
//
load_list.onFault = function (e) {
trace ("failed: " + e.faultstring);
};
}
function startClass (myClassName, slideAr) {
//
classAr[0] = new [myClassName] (slideAr);
}
My class constructor is just tracing a string for testing.

Is there a way to instantiate a class in an array I've already declared, then delete it and make a new class in the same element?
or am I making this way too complicated...
Thanks
- Kiwi

Instantiate Class
Hi

Im trying to instantiate a class called Favourites_panel1 from FavouritesPanel.
Im passing an argument into FavouritesPanel to call te relevant class for which style of panel to create.

Im getting this error when attempting it....


Quote:




TypeError: Error #1007: Instantiation attempted on a non-constructor.




The code for each class is below...

FavouritesPanel.as


Code:
package {

import flash.display.Sprite;
import favourites_classes.*;

public class FavouritesPanel extends Sprite {
private var _type:String;

function FavouritesPanel($type:String = 'Favourites_panel1') {
// different type for different sections
_type = $type;
init();
}

private function init():void {
var targetClass:String = String(_type);
var duplicate:* = new [targetClass]();
}
}
}
And this is the class tat extends the above, and that want instantiated when the above tries to....

Favourites_panel1.as


Code:
package favourites_classes {

public class Favourites_panel1 extends FavouritesPanel {

function Favourites_panel1() {
trace(' i have been ccreated');
}

}
}
ANy help is greatly appreciated!!

Instantiate Class
Hi

Im trying to instantiate a class called Favourites_panel1 from FavouritesPanel.
Im passing an argument into FavouritesPanel to call te relevant class for which style of panel to create.

Im getting this error when attempting it....

Quote:
TypeError: Error #1007: Instantiation attempted on a non-constructor.
The code for each class is below...

FavouritesPanel.as

Code:
package {

import flash.display.Sprite;
import favourites_classes.*;

public class FavouritesPanel extends Sprite {
private var _type:String;

function FavouritesPanel($type:String = 'Favourites_panel1') {
// different type for different sections
_type = $type;
init();
}

private function init():void {
var targetClass:String = String(_type);
var duplicate:* = new [targetClass]();
}
}
}
And this is the class tat extends the above, and that want instantiated when the above tries to....

Favourites_panel1.as

Code:
package favourites_classes {

public class Favourites_panel1 extends FavouritesPanel {

function Favourites_panel1() {
trace(' i have been ccreated');
}

}
}
ANy help is greatly appreciated!!

Instantiate PushButton From Class
I'm able to instantiate and control a Button component from my (AS2) class via:
stopBtn = stage_mc.createClassObject(Button, "stop", 1);

But I'm having problems with a PushButton. Simply trying:
stopBtn = stage_mc.createClassObject(Button, "stop", 1);

gives this error:
There is no property with the name 'FPushButtonSymbol'.

Enclosing FPushButtonSymbol in quotes eliminates the error but doesn't create the button.

I notice that the 'Button' component's linkage is different than the PushButton...the linkage name is greyed out for the Button and they sit in different folder levels in my library.

What special handling is required for control of the PushButton.

[F8] Instantiate Class Dynamically
My problem is instantiating a class. The class should start after a succesful load to a webservice. However I cannot figure out how to instantiate my class.

My idea was to create an array on the keyframe, then make an element of that array my class.

*NOTE; I have already done the load functions for the web service. It does load properly, and I don't get any error messages.


Code:
import mx.services.WebService;
import classes.*;
//
var manage_ws:WebService = new WebService ([link]);
//
var classAr = new Array(0);
//
load_list = manage_ws.GetSlidesForSlideType (localID, sID[1]);
//
load_list.onLoad = function (list) {
var className = list[0].SwfFileName.split (".swf");
var cName = className[0];
//
startClass (cName, list);
};
//
load_list.onFault = function (e) {
trace ("failed: " + e.faultstring);
};
}
function startClass (myClassName, slideAr) {
//
classAr[0] = new [myClassName] (slideAr);
}
This is my class below, just a constructor that trace for testing

Code:
class top5 {

public function top5 (listOfSlides){
trace("I was loaded");
}
}
Is there a way to instantiate a class in an array I've already declared, then delete it and make a new class in the same element?
or am I making this way too complicated...
Thanks
- Kiwi

Instantiate An AS2 Class Which Is A MovieClip?
I have a simple class which extends MovieClip and requires one constructor argument, we'll call Box. This class is associated to a MovieClip in the library. I can't for the life of me figure out how to actually instantiate it at runtime:

new Box('hello world'); // doesn't work, the MovieClip is never attached on stage
attachMovie('Box',getNextHighestDepth()); // attaches, but doesn't pass constructor argument

How should this be done?

How Do I Delete And Re-instantiate A Class
I have a singleton class that loads in an XML file containing initial states for the files that are loaded in my application. When the user selects a module from a menu, this class is instantiated with the appropriate XML file. The problem I'm having is that after the user has run one of the modules, when they select another module, the states aren't reloaded from scratch. Can someone please tell me what I'm doing wrong in the code below?

In the class itself:

Code:
// ActionScript Document
//IMI State Management Object
class images.classes.stateManager {
static var instance:stateManager;
var CURRENTLOADED:String = "NO";
var GLOBALLOADED:String = "NO";
var DOCSPARSED:Number = 0;
var currentInit:String = "";
var stateArray:Array = new Array();
var Initializer:Array = new Array();
var stateReady:Boolean = false;
var inited:Boolean = false;
//variables for overRiding XML values
var overRide:String = "0";
var overRideLOADED:String = "0";

public function getStateReady():Boolean {
return this.stateReady;
}
public static function getInstance(xmlFile:String):stateManager {
if (instance == null) {
instance = new stateManager(xmlFile);
}
return instance;
}
private function stateManager(fName:String) {
this.currentInit = fName;
this.initStateManager();
}
public function deleteInstance() {
instance = null;
CURRENTLOADED = "NO";
GLOBALLOADED = "NO";
DOCSPARSED = 0;
currentInit = "";
CURRINIT = "";
IDs = 0;
initCheck;
initCheck2;
initCheck3;
currentLRU = null;
InitScript;
InitScript2;
stateArray = new Array();
Initializer = new Array();
stateReady = false;
inited = false;
//variables for overRiding XML values
overRide = "0";
overRideLOADED = "0";
}
function initStateManager() {
if (inited != true) {
var rootApp = this;
this.InitScript = new XML();
this.InitScript.ignoreWhite = true;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
initCheck = setInterval(this, "loadGLOBAL", 50);
initCheck2 = setInterval(this, "resetInit", 50);
}
}
function loadGLOBAL() {
if (this.CURRENTLOADED == "YES") {
this.CURRINIT = this.currentInit;
this.currentInit = "./InitFiles/global.xml";
this.DOCSPARSED ++;
var rootApp = this;
var INIT = this.currentInit;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
clearInterval(initCheck);
}
}
function resetInit() {
if (this.GLOBALLOADED == "YES") {
this.currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is ready"+newline;
//this.reportStateNew();
this.GLOBALLOADED = "NO";
clearInterval(initCheck2);
}
if (this.overRideLOADED == "1") {
currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is now ready"+newline;
overRideLOADED = "0";
clearInterval(initCheck3);
}
}
function ParseXML(nextNode) {
while (nextNode<>null) {
var lastNode:XMLNode = nextNode;
nextNode = ParseCase(nextNode);
if (nextNode == null) {
if (lastNode.parentNode.nextSibling<>null) {
nextNode = lastNode.parentNode.nextSibling;
}
}
}
if (this.overRide != "1") {
if (this.DOCSPARSED == 1) {
this.GLOBALLOADED = "YES";
this.DOCSPARSED++;
} else {
this.DOCSPARSED++;
this.CURRENTLOADED = "YES";
}
} else {
this.overRide = "0";
this.overRideLOADED = "1";
}
if (this.GLOBALLOADED == "NO" && this.currentInit.indexOf("Global") != -1) {
this.GLOBALLOADED = "YES";
}
}
}
In my main file:

Code:
dropDown.onChange = function() {
_global.stateManager.deleteInstance();
_global.stateManager = null;
//Copied from NAV button!
_global.currentUnit = "";
currItem = ModuleArr[Number(eventObj.target.value)];
newMenu_mc.moduleName_txt.text = currItem.split(",")[0];
currModule = currItem.split(",")[1];
gotoAndStop(2);
_root.currentInit = currModule;
_global.currentInit = "./InitFiles/"+currModule+".xml";
_global.stateManager = stateManager.getInstance(_global.currentInit);
_global.stateManager.newXML(_global.currentInit);
}

Instantiate Class Using String
In AS2, you could write: attachMovie("someLibraryItem", ...), and this would create an instance on the _root accessible by _root.someLibraryItem. Is this possible using AS3? I know the standard way is to just do: var foo:LibraryItem = new LibraryItem(), but I'd like to be able to create an instance of a class and have its name be defined by a string. I'd like to do this:

root["circle" + i] = new MovieClip(); //causes a run-time error

I noticed that the following is still legal in AS3:
trace(root["circle1"]); //works as expected

Is there any way to do this? I noticed that the "name" property of all DisplayObjects is read-write, but it doesn't seem that changing the name has any effect on the instance name. Any help would be greatly appreciated!

Andy

Instantiate Class By Variable?
I need to instantiate a class based on a variable, how can this be done?

How Do I Delete And Re-instantiate A Class
I have a singleton class that loads in an XML file containing initial states for the files that are loaded in my application. When the user selects a module from a menu, this class is instantiated with the appropriate XML file. The problem I'm having is that after the user has run one of the modules, when they select another module, the states aren't reloaded from scratch. Can someone please tell me what I'm doing wrong in the code below?

In the class itself:

Code:
// ActionScript Document
//IMI State Management Object
class images.classes.stateManager {
static var instance:stateManager;
var CURRENTLOADED:String = "NO";
var GLOBALLOADED:String = "NO";
var DOCSPARSED:Number = 0;
var currentInit:String = "";
var stateArray:Array = new Array();
var Initializer:Array = new Array();
var stateReady:Boolean = false;
var inited:Boolean = false;
//variables for overRiding XML values
var overRide:String = "0";
var overRideLOADED:String = "0";

public function getStateReady():Boolean {
return this.stateReady;
}
public static function getInstance(xmlFile:String):stateManager {
if (instance == null) {
instance = new stateManager(xmlFile);
}
return instance;
}
private function stateManager(fName:String) {
this.currentInit = fName;
this.initStateManager();
}
public function deleteInstance() {
instance = null;
CURRENTLOADED = "NO";
GLOBALLOADED = "NO";
DOCSPARSED = 0;
currentInit = "";
CURRINIT = "";
IDs = 0;
initCheck;
initCheck2;
initCheck3;
currentLRU = null;
InitScript;
InitScript2;
stateArray = new Array();
Initializer = new Array();
stateReady = false;
inited = false;
//variables for overRiding XML values
overRide = "0";
overRideLOADED = "0";
}
function initStateManager() {
if (inited != true) {
var rootApp = this;
this.InitScript = new XML();
this.InitScript.ignoreWhite = true;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
initCheck = setInterval(this, "loadGLOBAL", 50);
initCheck2 = setInterval(this, "resetInit", 50);
}
}
function loadGLOBAL() {
if (this.CURRENTLOADED == "YES") {
this.CURRINIT = this.currentInit;
this.currentInit = "./InitFiles/global.xml";
this.DOCSPARSED ++;
var rootApp = this;
var INIT = this.currentInit;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
clearInterval(initCheck);
}
}
function resetInit() {
if (this.GLOBALLOADED == "YES") {
this.currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is ready"+newline;
//this.reportStateNew();
this.GLOBALLOADED = "NO";
clearInterval(initCheck2);
}
if (this.overRideLOADED == "1") {
currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is now ready"+newline;
overRideLOADED = "0";
clearInterval(initCheck3);
}
}
function ParseXML(nextNode) {
while (nextNode<>null) {
var lastNode:XMLNode = nextNode;
nextNode = ParseCase(nextNode);
if (nextNode == null) {
if (lastNode.parentNode.nextSibling<>null) {
nextNode = lastNode.parentNode.nextSibling;
}
}
}
if (this.overRide != "1") {
if (this.DOCSPARSED == 1) {
this.GLOBALLOADED = "YES";
this.DOCSPARSED++;
} else {
this.DOCSPARSED++;
this.CURRENTLOADED = "YES";
}
} else {
this.overRide = "0";
this.overRideLOADED = "1";
}
if (this.GLOBALLOADED == "NO" && this.currentInit.indexOf("Global") != -1) {
this.GLOBALLOADED = "YES";
}
}
}
In my main file:

Code:
dropDown.onChange = function() {
_global.stateManager.deleteInstance();
_global.stateManager = null;
//Copied from NAV button!
_global.currentUnit = "";
currItem = ModuleArr[Number(eventObj.target.value)];
newMenu_mc.moduleName_txt.text = currItem.split(",")[0];
currModule = currItem.split(",")[1];
gotoAndStop(2);
_root.currentInit = currModule;
_global.currentInit = "./InitFiles/"+currModule+".xml";
_global.stateManager = stateManager.getInstance(_global.currentInit);
_global.stateManager.newXML(_global.currentInit);
}

Can't Instantiate A Class From Within My Document Class
My classes work when I link them to Movie clips, but when I try the below code I get an error:

package {
import flash.display.MovieClip;
import flash.ui.Mouse;
import Enemies;
//
public class VertShooter extends MovieClip {
public var _enemy:Enemies;
//
public function VertShooter () {
trace ("VertShooter Class");
Mouse.hide ();
//
_enemy = new Enemies();
addChild (_enemy);
}
}
}
/////////////////////////

Please help, thanks!

Dynamically Instantiate Custom Class
A: The Problem
1) I have an array of values formated as such [1,0,5,1,7,1,1,0...]
2) I have a series of custom classes named Tile0, Tile1, Tile2...
3) I have a var classString that is a concatenation of the string "Tile" with whatever value I am pulling from the index.
4) I wish to instantiate one of the classes from 2) with the dynamically created string in 3)

B: Tested Solutions
1) If I hard code the class names from A:2 they instantiate correctly, so I know they are working
2) The problem is strictly related to instantiating a class from a variable
3) I did a search here last night and returned one thread on the subject (link), but was not able to successfully implement that technique do to lack of details.

Does anyone know how to do this??

Instantiate A MC From Actionscript?
hey guys,
so I made a puff of smoke. It's just a tween of a smoke image that resizes over the course of 30 frames. Whatever. It sits in my library with the name Smokewhisp. It is a movie clip.
I have a Document class AS document, and it involves multiple functions. Basically, all I want to do is be able to create instances of the Smokewhisp movieclip when the mouse activates other events that are in the document class file:
The mouse gets close enough to a link, which is hiding behind a logo: check
The text jumps out from behind the logo and gets closer to the mouse: Check
When the text moves towards the mouse away from the logo, that is when i want the Smokewhisp to be instantiated: Not check.

In the library I DID set the Smokewhisp as "export for actionscript" and I didn't change it's name (should I have done that?) or base class. All I want to know how to do is instantiate it. I have all the other stuff taken care of, and once I can get the freaking thing to appear on the STAGE, then I can do everything else on my own.
Thanks for any help!! You guys have helped me a ton...
--L

Instantiate Loaded Swf
I want to load a Custom swf witch has some functions by itself.So i do the following to load it:

Code:
var pictURL:String = "cl.swf";
var URLReq:URLRequest = new URLRequest(pictURL);
public var pictLdr:Loader;
pictLdr.load(pictURLReq);pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE,check);
how do i instantiate this swf?I want to do that because it has some custom functions itself.

Instantiate From LoadMovie
Hi. Is it possible to attachMovie from a swf loaded with loadMovie? My initial tests did not work.

Instantiate AS2 Subclass Of MovieClip?
I can't figure this out. I have a simple class which extends MovieClip, something like this:

ActionScript Code:
class Box extends MovieClip{
    function Box(size){
        trace(size);
    }
}

I have a library item associated with this class. How do instantiate this class and pass the size parameter?

Instantiate MovieClip From Name String
I want to instantiate lots of MC's based on their name (linkage idetifier) that I would get from an XML as String .
How can I do that ? (without xml ,i think I'll figure that out)

Thanks

How Do I Use Fuse To Instantiate PennerEasing?
Ok I am trying to change over old code (Actionscript 1.0) to use Fuse in Flash 8.

Old code uses things like this:

this._x = Math.easeInQuad(this.t, 0, gox, 6);

So my new code in Flash 8 would be this?:

import com.mosesSupposes.fuse.*;
ZigoEngine.register(PennerEasing);
this._x = PennerEasing.easeInQuad(this.t, 0, gox, 6);

Is that all I need to do to do an easeInQuad as was done in older version of the code? Do I have to declare/define it somewhere or is the equations, parameters it accepts builtin to Fuse?

Thanks.

How Do I Use Fuse To Instantiate PennerEasing?
Ok I am trying to change over old code (Actionscript 1.0) to use Fuse in Flash 8.

Old code uses:

this._x = Math.easeInQuad(this.t, 0, gox, 6);

So my new code in Flash 8 would be:

import com.mosesSupposes.fuse.*;
ZigoEngine.register(PennerEasing);
this._x = PennerEasing.easeInQuad(this.t, 0, gox, 6);

Is that all I need to do to do an easeInQuad? Do I have to declare/define it somewhere or is the equations, parameters it accepts builtin to Fuse?

Thanks.

Dynamically Instantiate A MovieClip I Have In Library?
Hi,
i try to make a standalone application where the user can create dynamicly (by pressing a button for example) a dragable component in the page.
I've made a movieClip called "postit" in my library, and activated the option "export for actionscript" and i give the linkage name "postit".

on the code of my button, i have :
attachMovie("postit","mypostit",1000);

but i want to create a different instance each time i click the button!

even if i do something like
attachMovie("postit","mypostit"+x,1000);
where x change at each click, the component seems to override the one created before, and only one appear at a time.

Does anyone have idea how i can correct that?
or where i can find a good tutorial for advanced actionscripting?

Thanks a lot (and sorry for bad english!)

Need To Instantiate An Image In An Empty Mc Within A Button
Hi,

I dont know why I cant access an instance of a mc within a button.

I have an empty mc called "theEmpty" and another one containing a image called "theImageA" (exported to ActionScript). I have a button called "theButton" too.

I instantiated the mc "theEmpty" within first frame of "theButton" and named its instance as "TheEmpty1".

Then, I instantiated "theButton" in the first frame of the timeline and named its instance as "TheButton1".

In the first frame of the timeline, I coded the following:


theButton1.theEmpty1.attachMovie("theImageA","theI mageA1",2);


The idea should load the mc "theImageA" in the mc "theEmpty" that is within the button "theButton". Why it dont works????

Thanks!

Symbol Exported For AS, Can't Instantiate In AS File
I'm exporting a number of symbols for Actionscript from the library. When I try to create instances of them in a separate (imported) actionscript file:

Code:
private var gothamBook:Font = new GothamBook();
private var logo:MovieClip = new logo();

I get an error 1180 - call to possibly undefined method - for "logo" (twice), but no problem with the font.

I have no problem creating an instance in my document class, only in an additional class that is imported into the document class.

I tried instantiating in other external AS classes - same problem. Only seems to work in the document class.

I just started working with a document class, so I may be missing something key in the way I export for actionscript or otherwise connect to the document class.

Any ideas?

How To Instantiate A MovieClip From The Library At RunTime?
Hello,

For my application I have several MovieClip items I have created with different animations and similar stored in the library. I need (at runtime) a way to create / instantiate these clips. Something like:

var mc:MovieClip = new MovieClip();
addChild(mc);

but a specific item from my library. Something like this would be perfect:

var bottle:MovieClip = new MovieClip("GatoradeBottle");
addChild(bottle)

Of course that does not works. I am using Flash CS3 and ActionScript 3.

Thanks,
Jorge

How To Instantiate/use A Dynamic Text Field Within An Mc
Hi,

This is probably very straightforward but can anyone give me a bit of help with this??

I've an mc in main FLA file library called MaskInter which is linked to MaskInter.as which contains very simple constructor:


ActionScript Code:
package
{
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.ui.*;
    import flash.text.TextField;
   
    public class MaskInter extends MovieClip 
    {
       
        public function MaskInter()
        {
           
                       
        }
       
    }
}

this is then used by my main doc class, Example.as, like so:


ActionScript Code:
var maskInter:MaskInter = new MaskInter;
stage.addChild(maskInter);

Now, there's a dynamic text field(with instance name plTimer) on the MaskInter mc in FLA lib and what I want to know is how do I instantiate/use that in my as files? Does it need to be created in the constructor??
I was trying something like maskInter.plTimer.text in the Example.as file but this is clearly not working..

Appreciate any help..

Instantiate A Movieclip Passed As A Parameter
I am passing a movieclip as a parameter in an object but I can't get it to work properly


ActionScript Code:
public function CustomButton(obj:Object)
{
    /*
    this is what I am trying to attach, but I don't which icon I will receive
    var icon:EmailIcon = new EmailIcon();
    */
   

    // This doesn't work       
    var iconClass:Class = obj.icon as Class;
    var icon:MovieClip= new iconClass();
           

    iconHolder.addChild(icon);
}

Can You Instantiate An ActiveX Object From Inside Of Flash?
is this possible? If so, how and what are the limitations??? THanks.

Can You Instantiate An ActiveX Object From Inside Of Flash?
If so what are the limitations? Thanks.

Simple MovieClip Instantiate.. Help Me Stay Sane
Hi there, I posted on here yesterday but am still unable to perform this basic operation in as3, and its driving me crazy, maybe you can help!

I've got this code in an AS file in the same folder as my FLA -


Code:
package {

import flash.display.MovieClip;
import flash.text.TextField;

public class Mybtn extends MovieClip{

public function Mybtn(xPos:int, yPos:int, n:String){
var theButton : MovieClip = new MovieClip();
this.addChild(theButton);
this.x=xPos;
this.y=yPos;
this.name=n;
trace("it lives!");
}
}
}
And a MovieClip in my library with the linkage 'theButton' and base class 'flash.display.MovieClip'.

I've then put in the first frame of my FLA, the following -


Code:
var buttonOne = new Mybtn(50,50, "My First Freakin Button");
Yet still no movie on the stage! I've cut down my code and the amount of info from what I posted yesterday and I'm sure this should work.. I basically want to create a method i can call that'll instantiate a movieclip (which is my interface's button) and be able to pass arguments regarding positioning, and also a string in order to fill in a dynamic text field inside the MC. PLEASE HELP!


Thanks for your time,

Will

Default Parameter Values - Can't Instantiate Classes As Defaults
What's the proper way to go about doing something like this?:

ActionScript Code:
public function RangeSelector( pStart:Date = new Date() ):void

I'm not sure how to set up my function so that it accepts a Date, but to default to a Date if none is passed.

Thanks in advance for any help!
k.

Accessing A Movie From Another Movie (class)
Hi all!,

Ok, this is a little bit complicated to explain, but I will try my best. First, please click on the link below to see the mockup that I did:
Link to mockup

Now for some explanation:
First of all, the Flash makes use of an XML file to grab some data. This part was freakin complicated and it's actually a programmer who helped me with that but he is very unfamiliar with AS on the whole so he couldn't really help me with the rest. OK so basically in the first frame I am loading the XML, then what you are seeing on the stage is in frame 2.

on the stage there are 2 movies:

1. scrollPane_mc
2. cables_mc

For now you can check and uncheck the items in the scroll pane and you can roll over the cables to see their names.

1. scrollPane_mc
scrollPane_mc is a scroll pane component that has a movie called cableList_mc as source.

cableList_mc itself is an empty movie with just 1 frame and which dynamically grabs a movie called cableListItem_mc (itself attached to a class of the same name) from the library and duplicates it, based on data from the XML file.

code in cableList_mc:
var startY:Number = -0.8;

for (var cableName:String in VPN_Utils.cables) {
var listItem:cableListItem_mc = new cableListItem_mc();
listItem.name = cableName;
listItem.x = 0;
listItem.y = startY;
listItem.cableNameText.text = VPN_Utils.cables[cableName][0];
addChild(listItem);
startY += 18;
}

code for cableListItem_mc.as (1 cableListItem_mc is basically 1 checkbox item):
package {

import flash.display.*;
import flash.events.*;
import flash.text.TextField;
import VPN_Utils;

public class cableListItem_mc extends MovieClip {

private var checked:Boolean = true;

public function cableListItem_mc() {
addEventListener (MouseEvent.MOUSE_DOWN, swap);
}

private function swap(e:MouseEvent):void {

if (checked) {
this.gotoAndStop(2);
} else {
this.gotoAndStop(1);
}
checked = !checked;
trace (this + " " + this.name + " is " + checked);
}
}
}

2. cables_mc
cables_mc on the other hand just contains several movie clips, placed manually on the stage and all of them based on the class VPN_Cable.as

code for VPN_Cable.as:
package {

import flash.display.*;
import flash.events.*;

public class VPN_Cable extends MovieClip {

public function VPN_Cable() {
addEventListener (MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener (MouseEvent.MOUSE_OUT, onMouseOut);
}

private function onMouseOver(e:MouseEvent):void {
text_mc.visible = true;
}

private function onMouseOut(e:MouseEvent):void {
text_mc.visible = false;
}

}
}

So basically now what I want to achieve is to control and talk to the cables from the scroll pane. So when I uncheck "Cable 1" in the scroll pane, "Cable 1" on the stage should turn invisible for example.

I hope this is clear....

Thanks a lot! in advance!

jon.

How Do I Access A Movie From Another Movie (class?) ?
Hey all,

I really need some help about this. AS3's driving me crazy O.o
ok, please see the attached image. This is basically my setting (in reality more complicated, but it's basically something like this).

So based on my image, i am trying to get paul_mc to talk to stef_mc. How do I do this??

All the script on paul_mc is found in a class which is something like this (simplified):

----------------------------------------------
package {

import flash.display.*;
import flash.events.*;

public class cableListItem_mc extends MovieClip {

public function cableListItem_mc() {
addEventListener (MouseEvent.MOUSE_DOWN, swap);
}

private function swap(e:MouseEvent):void {

// talk to stef here

}
}
}
------------------------------------------------

Thanks a lot in advance...













Attached Images

Class And Movie Clip
Hi,

I have 2 questions about movie clips and classes.

1. Is it possible to create an empty movie clip and load into it in run time an external graphic and register the new movie clip with a class ?

2. If i load into a movie clip an external movie clip which include in it an empty movie clip and i want to change the graphics in it, is it possible to do it and how?

the following example show what i tried to do:
first load into movie clip "mc" the file "external mc"
_root["mc"].loadMovie("external mc",1);
now i want to load something into movie clip "empty" inside "external mc"
_root["mc"]["empty"].loadMovie("a new graphics mc"]);

after this command nothing change on the screen

Thanks
Hadass

Movie Clips Like Class(oop)
hello
I have problems for make this:
structure:
Scene1
(script in 1º frame)
[[code]]
trace(ocomp.RetornaHtmlIntroConteudo(46));
(script no 2º frame)
[code]
if(ocomp.RetornaHtmlIntroConteudo != ""){
trace(ocomp.ohtmlintro.HtmlIntroConteudo);
stop();
}else{
trace("loading");
}
-- ocomp (movie clip instance)
(script no 1º frame)
[code]

function RetornaHtmlIntroConteudo(id_detailing_cycle){
var x;
x = "teste";
ohtmlintro.HtmlIntroConteudo = x;
return x;
}



--ohtmlintro (movie clip instance)
(script no 1º frame)

[code]

var HtmlIntroConteudo = "";



well, the property ohtmlintro.HtmlIntroConteudo be undefined when I call "RetornaHtmlIntroConteudo". somebody may help?


thanks

Gustavo

Using Debug Movie With Class?
I have a class in a separate actionscript file called "GameTile.as"

If I use debug movie, it seems to only test breakpoints INSIDE the FLA. It doesn't ever run through break points in the class.

Is it possible to do this? or is this some major flaw with flash?

Loading A Movie From A Class
I am trying to figure out how to make a class that will load a movieclip from the library to the stage

I want to do something like:

var loader:Loader = new Loader();
loader.loadClip("clip name here");

Does anyone have any ideas how I can do this or point me in the right direction? I have looked through many tutorials but I cannot find one that implements this in a class.

Linking Class And Movie
Hi every body,
i am just starting AS2 programming and tried to link movie clip with a class file but shows following error while i run it.

**Error** Symbol=Symbol 1, layer=Layer 1, frame=1:Line 1: The class or interface 'Drag.as' could not be loaded.


i have got two files.

first Drag.as.

class Drag extends MovieClip {
function Drag() {
onPress = drag();
onRelease = drop();
}
function drag() {
this.startDrag(false);
}
function drop() {
this.stopDrag();
}
}


and secondly clip1.fla

i have created a movie clip and linked it as Drag.as in AS2 classes in Linkage properties. Both files are in same folder

any suggestions, please help me.

thanks every body

Movie Clip Class
Hello, I'm trying to create a variable called pic1 in a for loop to control positions of an object from box i of an array.

This array has 16 boxes with a movie clip in each. Because my movie clips are all different they all have names from p1 to p16. So when I write my code:


ActionScript Code:
for(var i:int = 0; i < numPics; i++) {
        var pic0:p1 = pics[i];
        for(var j:int =  i + 1; j < numPics; j++) {
            var pic1:p1 = pics[j];

this can't work as the variable needs to reference to all of the objects in the Array pics. So tried substituting p1 with MovieClip:


ActionScript Code:
for(var i:int = 0; i < numPics; i++) {
        var pic0:MovieClip = pics[i];
        for(var j:int =  i + 1; j < numPics; j++) {
            var pic1:MovieClip = pics[j];

This doesn't work. I'm not sure what else to try. Does anyone know what I could do here?

Attach Movie Using Class
i want to attach movie any where so i want to built a class

class Class_AttachMovie
{
function create1(attachIN:MovieClip, movName:MovieClip, newName:String, newDepath:Number)
{
attachIN.attachMovie(movName,newName, newDepath);
}
}

there is some error of Type mismatch.

My Own Movie Clip Class?
HI,

I have made a 3-d model in Flash of an office, where one can walk around hallways, etc. The initial version was made doing everything "inside of the fla". Now I am trying to accomplish the same thing using a class structure.

I have made a class called Room. What I want this class to do is, I send it the names of external swf files, one for the floor, ceiling, left, right and back walls and it is supposed to return the "room". This code works IF I create empty movie clips (which are then populated with the external files) that are tied to the _root.

Now, the way my application works, each room is a hallway segment. Each hallway segment's "backwall" has the next segment loaded into it, at a quarter of the size (so you can see all the way down and it's created dynamically). Because of this I obviously can't tie my empty movie clips to the _root because the second will replace the first and so on.

I'm obviously misunderstanding something here, but I thought that when I write:

class Room extends MovieClip {

that I now have at my disposal, the MovieClip object referenced by the name "Room". That "Room" IS now a MovieClip. If that's the case, when I trace this._name which returns a MovieClips instance name, it should return my Room's name given in the fla file - ie myRoom1=new Room(); should return "myRoom1" in a trace. Instead it returns undefined.

Inside of my class, I create an empty movie clip for each part (3 walls, ceiling and floor) and I need those to be referenced to the Room that is instantiated by myRoom1=new Room();

How do I do this????

Thanks!

Assigning Class To Movie Clip
Hello there.

Since I like OOP I always write a lot of classes and declare them with the Object.registerClass() thing. Now I wonder if it's possible to assign a class to a movieclip that already exists?

Another thing:
How do I create labels on frames I've been working in flash for over a year and I still don't know how to do that, which is very frustrating when you decide to add something to a game and you need to make a new frame and every gotoAndStop gets spoiled

Thanks

Movie Clip Reference Within A Class
Having problems dynamically creating a movieclip reference to pass to another class.

Basically I have a Game class and a Boiler class. The Game class contains a property called "mcReference" which is being created correctly as "_level0.game_mc" when I create the Game instance

var myGame = new Game(this);

Within the Game class I have a method to create 9 Boiler instances.

i.e


Code:

public function create_Boilers():Void {

arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i + 1) +
"_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}
If I do a trace on vBoilerRef, I get undefined.

Any ideas what I am doing wrong?

The code for the 2 classes is as follows:


Code:

import Boiler;

class Game extends MovieClip{


// -----------
// Constructor
// -----------



public function Game(passed_mcReference:MovieClip) {


mcReference = passed_mcReference;
trace ("Game mcReference = " + mcReference);


}

public var mcReference:MovieClip;
public var arrBoilers:Array;
public var numBoilers:Number


public function init():Void {

numBoilers = 9;

}



public function create_Boilers():Void {


arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i
+ 1) + "_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}

}
##############################


Code:


class Boiler extends MovieClip{


// -----------
// Constructor
// -----------



public function Boiler(passed_mcReference:MovieClip,
passed_ID:Number) {


mcReference = passed_mcReference;
trace ("Boiler mcReference = " + mcReference);
numID = passed_ID;
trace ("numID = " + numID);



}

public var mcReference:MovieClip;
public var numID:Number;
private var numInitialRotation:Number = -83.5;


public function reset_Needle():Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}


public function set_Needle_Rotation(passedRotation:Number):Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}

}

Movie Clip Name For Custom Class
I did this cool animation for a movie clip and now I'm tying to make it a class. It's nothing great but I'm proud of it. But now I'm just (fowl language) at this thing. I need to get the x and y pos of the movie clip at the beginning. The problem is I don't know how to get the name of the clip, and I don't want the user to have to do two functions. right now I have code like this:

public function moveClip(clip,endX,endY,sec){
//my code.
}

So i'm already getting the clips name, end position, and seconds. The problem is that I need the beginning positions but cant put it in this function because it messes it up. So I write a private function to be used in the class but what do I put in this function to obtain the start x and y of the clip? Or can I?

MovieClipLoader Class Shwoing Movie Too Soon
I'm using a MovieClipLoader to load in a swf file... but the problem is that it shows the swf when it's only loaded 23% of it... is there anyway to get it to not show any of the movie until it's FULLY loaded?

Embed Root SWF With Doc Class In Movie
Hi folks,

This is for the most part my first time using AS3 so bear with me. I am trying to integrate a dynamic picture viewer into my main flash movie, but the viewer references a document class and I am not experienced enough with this to know what I need to do in order to get it to work correctly. I can of course link the viewer from the main movie and open it in a new window, but I'd much rather have it embedded in the main movie itself. The main movie for the most part only has bare bones as3, stopping the movie where need be, a preloader and button control. When I try and apply the document class to the main movie (copying the relevant frames over from the image viewer) I get all sorts of errors. I'll go into more depth if need be (that is to say if someone gets the gist of what Im saying and can help).

Here is the main movie link: http://www.theleaguemediagroup.com/working.html
and here is the viewer: http://www.theleaguemediagroup.com/imageviewer.html

Thanks in advance to anyone that can help with this issue!!!

Class Trying To Attach A Movie To The Stage
I am just trying to attach a simple movieClip to the stage in a class file:


Code:
class ImageViewerMain extends MovieClip {
// Constants:
public static var CLASS_REF = ImageViewerMain;
// Public Properties:
// Private Properties:
// var to pass from constructor func to loadImage func
private var newlyCreatedImgHolder_mc:MovieClip;
// Initialization:
// set constructor func
public function ImageViewerMain(targetImg_mc:MovieClip, targetThumb_mc:MovieClip, depth) {
// create the empty movie holder with a unique instnace name and depth
for (var i = 0; i<_level0.numOfItems; i++) {
// use the array previously created to set the imageToLoad var
var newImageToLoad = _level0.imageArray[i];
var newThumbToLoad = _level0.thumbArray[i];
// create as many empty movieClips as there are images in the XML with unique instance names
makeImageMovieClips(i, newImageToLoad, targetImg_mc);
/*var newImgClip_mc = targetImg_mc.createEmptyMovieClip("imgHolder_mc"+i, depth);
var newThumbClip_mc = targetThumb_mc.createEmptyMovieClip("thumbHolder_mc"+i, depth);
// load the imageinto the newly created movieClip
newImgClip_mc.loadMovie(newImageToLoad);
newThumbClip_mc.loadMovie(newThumbToLoad);
newThumbClip_mc._x = newThumbClip_mc._x+100;
targetImg_mc.imgHolder_mc5._alpha = 0;
// set them all to 0 alpha
//newClip_mc._alpha = 0
*/
}
}
// Public Methods:
public function makeImageMovieClips(i, newImageToLoad, targetImg_mc) {
var imgMovieClip = ["img_"+i];
trace('imgMovieClip = '+imgMovieClip+' will load '+newImageToLoad);
_level0.attachMovie("movieHolder", "movieHolder_mc"+i);
//_level0.loadMovie(newImageToLoad)
//_level0.imgMovieClip._x = targetImg_mc._x+100;
//btn.onPress = function() {
//trace(this);
//};
}
public function loadImage(img:String):Void {
newlyCreatedImgHolder_mc.loadMovie(img);
}
// Semi-Private Methods:
// Private Methods:
}
The linkage is this: movieHolder

What am I doing wrong? Thanks, dvl

Movie Clip Loader Class
Hi All -

I have a flash site and I want to preload all the external SWFs before the user sees the site. I think that only the first one is getting loaded and I'm not sure what I'm doing wrong with the rest. Here is my code, any help would be great.

Thanks,

Liza


import mx.transitions.Tween;
import mx.transitions.easing.*;

var mcl:MovieClipLoader = new MovieClipLoader();

var mclL:Object = new Object();

mclL.onLoadProgress = function(target,loaded,total) {
loader.percent.text = "Loading... " + Math.round((loaded/total) * 100) + "%";
}

mclL.onLoadInit = function() {
loader._visible = false;
loader.percent.text = "";
}

mcl.addListener(mclL);


mcl.loadClip("main2.1.swf", holder);
mcl.loadClip("about.swf", _parent);
mcl.loadClip("gallery.swf", _parent);
mcl.loadClip("press.swf", _parent);
mcl.loadClip("contact.swf", _parent);
var wide:Boolean = true;

holder.onLoad = function():Void
{
loader._visible = false;

var moveTween:Tween = new Tween(this, "_width", Strong.easeOut, this._width, 550, 1, true);
wide = false;

moveTween.onMotionFinished = function():Void
{
loader._visible = false;
var moveTween:Tween = new Tween(box, "_yscale", Strong.easeOut, box._yscale, 0, 1, true);
};
};

Attaching A Movie With A Class Instance
I am trying to make a class that when instantiated attaches a movie clip to the main timeline. So far I am just attaching the movie clip that is in my library to a movie clip variable, I'm not sure how to make the connection in my fla file.

for instance if I do,
var mcBalance:MovieClip = new Balance();
I would like the clip to be attached to the main time line at this point, then eventually I will have methods in the class to set the clip where I want it to be.


Code:
class Balance extends MovieClip {

private var mcBalance:MovieClip;

public function Balance(){
mcBalance.attachMovie("mcBalance","mcBalance",mcBalance.getNextHighestDepth());
}

public function update(nWeightLeftSide:Number,nWeightRightSide:Number){
this.nWeightLeftSide = nWeightLeftSide;
this.nWeightRightSide = nWeightRightSide;
}
}

Movie Loader Class Problem Help Me
im trying to create a class that loads movie clips then, moves to center and if theres another movie loaded before, it will tweens alpha of that movie to 0. here is the code. Since 2 two days im trying to make it work but i couldnt.

class has a method to load movie, addmovie(xpath)


ActionScript Code:
import mx.transitions.Tween
import mx.transitions.easing.*

class shell extends MovieClip{
   

    public function shell()
    {
    }
    ///-> class variables
    public var clipnewname:String = "mc"
    public var clipcount:Number = 0
    public var cliplist:Array = new Array
   
    public var prname:String = "pr"
    public var prcount:Number = 0
   
    public var distance:Number = 30
    private var duration:Number = 100;
    private var intervalId:Number
   
   
   
    public function addmovie(xpath)
    {
        clipcount++
        this.createEmptyMovieClip(clipnewname+clipcount,getdepth())
        var temp:MovieClip = this[clipnewname+clipcount]
        temp.loadMovie(xpath)
        clipcheckold()
        trace(temp)
    }
   
    private function clipcheckold()
    {
        if (clipcount == 1)
        {
            cliplist.push(this[clipnewname+clipcount])
            loadstart()
        } else {
            cliplist.push(this[clipnewname+clipcount])
            cliprem(this[clipnewname+(clipcount-1)])
            loadstart()
        }
    }
   
    private function clipshow(clip:MovieClip)
    {
            var mytween1:Tween = new Tween(clip ,"_x", mx.transitions.easing.Strong.easeOut,(((Stage.width-clip._width)/2)-distance),(Stage.width-clip._width)/2, 2, true);
            var mytween2:Tween = new Tween(clip ,"_y", mx.transitions.easing.Strong.easeOut,(((Stage.height-clip._height)/2)+distance),(Stage.height-clip._height)/2, 2, true);
            var mytween3:Tween = new Tween(clip ,"_alpha", mx.transitions.easing.Strong.easeOut,0, 100, 2, true);
    }
   
    private function clippreload()
    {
        if (this[clipnewname+clipcount].getBytesLoaded() == this[clipnewname+clipcount].getBytesTotal())
        {
            clearInterval(intervalId)
            clipshow(this[clipnewname+clipcount])
        } else {
            trace (int(100/(this[clipnewname+clipcount].getBytesTotal()/this[clipnewname+clipcount].getBytesLoaded())))
        }
    }
   
    private function loadstart()
    {
          intervalId = setInterval(this, "clippreload", duration);
    }
   
    private function cliprem(clip:MovieClip)
    {   
        var temp:MovieClip = this[clipnewname+clipcount]
        temp.swapDepths(clip)
        clip.removeMovieClip()
        var tmpArray:Array = new Array
        tmpArray.push(cliplist[1])
        cliplist = tmpArray
        clipcount = 0
    }
   
    private function getdepth():Number
    {
        return clipcount+1
    }

    ///-> Class End
}

How Do You Remove A Class From An External Movie?
Hello,

I've encountered an interesting problem and I haven't the foggiest idea whether what I need to do is even possible.

When I use loadMovie to load an external swf into my movie and then I remove the externally loaded movie, I have discovered that it leaves behind all of its custom class definitions... so when I go to load a different external movie that has its own versions of those those classes, it doesn't actually use its own versions.. it uses the versions from the first external file which has been removed!

So... Is there a way to completely purge any and all trace of a swf, including its custom classes, that you load with loadMovie?

Copyright © 2005-08 www.BigResource.com, All rights reserved