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




Calling Constructor In Condition: A Function Call On A Non-function Was Attempted.



Hi guys,Please help me somebody with this cos I have really no idea. I have made a simply condition calling a constructor of a class. Today I had to add an "else if", what caused the compilator to show me "A function call on a non-function was attempted."...
ActionScript Code:
function loadIt() {    if (var1 == "1") {        var a:SomeClass = new SomeClass(true);    } else if(var2 == "1"){         var a:SomeClass = new SomeClass(false); //<- if this is not here, everything works fine    } else {        var b:SomeOtherClass = new SomeOtherClass();        b.init();    }}
Any ideas? Thanks for any help!Poco



KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 03-12-2007, 11:04 PM


View Complete Forum Thread with Replies

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

[F8] Irritating Error: "A Function Call On A Non-function Was Attempted."
So I've been out of flash for a long time and I decided to hop back into it now that I have time again. I'm running on Flash 8 and I'm trying to make a simple particle engine. This simple, day or two project has turned into a nightmare I can't figure out.

For whatever reason, the colorTransform method of the Transform object is griping at me when I try to call it from a member function of the class I'm writing. I have this same code working in a different class, and the only difference I could see was that in the working code I was creating the Transform object on the fly for each color modification, as opposed to making it a property of the class.

Anytime I run the .colorTranform method, I get the error from the title on that line of code. I can't see to figure out what that even means exactly, let alone how to get rid of it. Has anyone encountered this before?

Here's what I have. I cut out the parts that don't pertain to this error (mostly sizing and speed code for the particle).


Code:
import flash.geom.Transform;
import flash.geom.ColorTransform;

class Particle
{
private var ColorInitial:ColorTransform;
private var ColorFinal:ColorTransform;
private var ColorCurrent:ColorTransform;

private var GraphicObject:MovieClip;
private var GraphicTransform:Transform;

function Particle(strQuality:String, intInitialX:Number, intInitialY:Number)
{
var newDepth:Number = _root.getNextHighestDepth();
_root.attachMovie("Particle" + strQuality, "dmParticle" + newDepth, newDepth);
this.GraphicObject = eval("dmParticle" + newDepth);

this.GraphicObject._visible = false;
this.GraphicObject._x = intInitialX;
this.GraphicObject._y = intInitialY;

this.PositionInitialX = intInitialX;
this.PositionInitialY = intInitialY;

this.GraphicTransform = new Transform(this.GraphicObject);

this.LifeBegin = 0;
}

function SetColor(ctfColorInitial:ColorTransform, ctfColorFinal:ColorTransform):Boolean
{
if (this.LifeBegin)
return false;

this.ColorInitial = ctfColorInitial;
this.ColorMedian = null;
this.ColorFinal = ctfColorFinal;

return true;
}

function Run():Boolean
{
this.LifeNow = new Date();

if (!this.LifeBegin)
{
this.LifeBegin = this.LifeNow.getTime();
this.ColorCurrent = this.ColorInitial;
this.GraphicTransform.colorTransform(this.ColorCurrent);
}

return true;
}
}

Function Calling From The _root But Call A Function Within A Instance
I have created a new instance 'Check_1' to work as a checkbox with a set of propertys and functions.

All ive done is created the functions in a script in the first frame of the instance-movie these are...

Simple......
================================================== =======

selected = -1;
function select_frame (FrameNum) {
gotoAndPlay (FrameNum);
}
function change_select () {
select_frame(2);
trace (selected);
}
function change_unselect () {
select_frame(1);
selected = -1;
}

================================================== =======

now from the _root i wish to call the above functions to change the instance propertys, it all works fine from within the instance but i also need to use the functions for that instance from the _root...

iv'e tried the follow with no joy...


_level0.Check_1.change_select()


Any light would be greatly appreciated.

Class Constructor Won't Call Function
Hello,

I attached a pared down version of my .as file, which is imported into my flash (.fla) file. I can't seem to call the initCircularArray function from my class constructor. The trace function in the initCircularArray never gets called, and the onLoad(success) trace returns 'true'. Any idea what I might be doing wrong?

Thanks,
Dave









Attach Code

class CircularArray {
var circularArray:Array = new Array();
public function CircularArray(inXML:String) {
var newXML = new XML(); //the XML file
newXML.load(inXML);
newXML.ignoreWhite = true;
newXML.onLoad = function(success:Boolean) {
if(success) {
trace("XML loaded: " + success);
initCircularArray(newXML);
}
}
}
public function initCircularArray(newXML:XML) {
trace("

GOT HERE

");
}
}

Calling Constructor Function Within Same Class
Dear users,
I have a document class name elevator and my constructor is also elevator as usual
How to call this constructor function within elevator class? Is is possible or not?
Please guide me on this.

Error Calling Javascript Function Using ExternalInterface.call
I'm attempting to execute Javascript code (the fromFlash() function) that's in an .HTM file, in which is embedded my .SWF file. I'm using the following code in the .FLA file:

PHP Code:



myButton.addEventListener(MouseEvent.CLICK, runExp);function runExp(e:MouseEvent):void { ExternalInterface.call("fromFlash");} 




When, from the .HTM file, I click myButton, I get the following error:

SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file:///C:/_Flash/email/email.swf cannot access file:///C:/_Flash/email/loadFlash.htm.

Any insights?

Thanks!

Instantiation Attempted On A Non-constructor
hi - I'm getting a very confusing error!

Everytime I Test or publish my movie it gives the same error:

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at Homepage2_fla::MainTimeline/Homepage2_fla::frame2()


The confusing part is, I don't have any scripts on any of my frame2s, the MainTimeline doesn't even have a frame2!

I've been through each movieclip thoroughly looking for any instations and I can't find a single one that is misplaced, infact I only have 5 very neat instantions on the same frame which are all for existing movies with linkages. I'm greatly confused as to which Frame 2 this error is on about.

If I have a movie on frame 1 of my main timeline and then play the movie from frame2 of its own timeline, will this movie then start on frame2 of the MainTimeline or Frame1 of the main timeline? Or even worse, will it start on frame3?

If anyone has any ideas for this, please let me know because I'm completely stumped!

Ta!
lump`

Instantiation Attempted On A Non-constructor
Code:
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.geom.ColorTransform;

public class Color extends Sprite
{
public var Picture:Class;

public function Color()
{
transformColor();
}

private function transformColor():void
{
var pic:Bitmap = new Picture();
addChild(pic);

pic.transform.colorTransform = new ColorTransform(-1, -1, -1, 1,
255, 255, 255, 0);
}
}
}
Using this as the document class for a separate fla file, i'm getting this error when the movie is exported:

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

why is this?

Instantiation Attempted On A Non-constructor. Argh
Hi,

I need a bit of help...

I have an xml document of data that gets fed into my flash file. In this xml document, I have a list of objects like:

<item id="item1" class="libApple"></item>
<item id="item2" class="libOrange"></item>
<item id="item3" class="libPear"></item>

My code reads this document and builds out the necessary objects. When I read in the data for the class attribute, it's a string. I need to use that attribute and create a clip of that class.

These classes (lib...) are sitting in the library of the flash document (movieclips set to export in first frame).

When I try:


Code:
var testClass:Sprite = new [strClassName];


strClassName is the value of the attribute after I read it in with code.

I get a "Instantiation attempted on a non-constructor" error for the above line.

When I replace [strClassName] with the actual class name like:

Code:
var testClass:Sprite = new libApple;


then that works.

How do I get around this? The thing is I don't know ahead of time what class it is until runtime so I can't just say "new libApple".

Thanks!!

Error #1007: Instantiation Attempted On A Non-constructor
Hello all,

I am building a prototype for depth control in AS3 and using CS3.

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at DepthControlT$iinit()
at Depthsortingtestv2_fla::MainTimeline/Depthsortingtestv2_fla::frame1()

this is my main FLA



ActionScript Code:
//this is just a test for depth sorting
//Dep'th sorting will be made by y axis
// run it through a sort function and draw in array order
import flash.display.MovieClip;
import flash.display.*;
import DepthControlT;

trace("Can you Hear MEE!!");

var Green:Green_MC = new Green_MC();
var Blue:Blue_MC = new Blue_MC();
var Yellow:Yellow_MC = new Yellow_MC();

addChild(Green);
addChild(Blue);
addChild(Yellow);

//var Depth:DepthControlT = new DepthControlT(GreenBox_MC, BlueBox_MC, YellowBox_MC, stage);
var Depth:DepthControlT = new DepthControlT();
addChild(Depth);

this is my .AS file

ActionScript Code:
public class DepthControlT extends Sprite
    {
        //public function DepthControlT(oGreen:Green_MC, oBlue:Blue_MC, oYellow:Yellow_MC, scene:Object)
        //public function DepthControlT(Green_MC, Blue_MC, Yellow_MC, scene:Object)
        public function DepthControlT()
        {
            trace("I can hear you!!!! Stop Yelling!!!");
            trace(Green_MC);
                        //MY PROBLEM IS THE FOLLOWING LINE
            var DepthArray:Array = new Array[Green_MC, Blue_MC, Yellow_MC];
}
       
   
   
}
}



I realize the problem is this line
//MY PROBLEM IS THE FOLLOWING LINE
var DepthArray:Array = new Array[Green_MC, Blue_MC, Yellow_MC];
How do I Instantiate? Were am I messing this up? Any help is much appreciated. Thank you very much!

TypeError: Error #1007: Instantiation Attempted On A Non-constructor.
Hello all,

I have been working on resolving a TypeError: Error #1007: Instantiation attempted on a non-constructor in Flash CS 4 / AS 3.0 .

I decompiled a file for a client because the original developer did not leave the .fla file.... so i am stuck with a bunch of weird syntax and playing guess ...

Here is the Error message in its entirety :

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at VidPlayer::UtilMethods$/createTextFormat()
at VidPlayer/loaderInit()

Here is the script in VidPlayer.as :

package VidPlayer{
import flash.display.*;
import flash.text.*;

public class UtilMethods extends Sprite {

public function UtilMethods() {
return;
}// end function

public static function createDynTextField(param1:String):TextField {
var _loc_2:TextField;
_loc_2 = new TextField();
_loc_2.type=TextFieldType.DYNAMIC;
_loc_2.autoSize=TextFieldAutoSize.LEFT;
_loc_2.embedFonts=true;
_loc_2.antiAliasType=AntiAliasType.ADVANCED;
_loc_2.multiline=true;
_loc_2.wordWrap=true;
_loc_2.mouseEnabled=false;
_loc_2.text=param1;
return _loc_2;
}// end function

public static function draw(param1, param2:uint, param3:int, param4:int, param5:int, param6:int):void {
param1.graphics.clear();
param1.graphics.beginFill(param2, 1);
param1.graphics.drawRect(param3, param4, param5, param6);
return;
}// end function

public static function createTextFormat(param1:int, param2:int, param3:Boolean, param4:Class, param5:int, param6:Number):TextFormat {
var _loc_7:*;
_loc_7 = new TextFormat();
_loc_7.font=new param4.fontName ;
_loc_7.size=param1;
_loc_7.bold=param3;
_loc_7.color=param2;
_loc_7.letterSpacing=param6;
_loc_7.leading=param5;
_loc_7.kerning=true;
return _loc_7;
}// end function

public static function setUpTextBitmap2(param1:String, param2:int, param3:int):Bitmap {
var _loc_4:*;
var _loc_5:BitmapData;
var _loc_6:Bitmap;
_loc_4 = new textNavMc();
_loc_4.nav_txt.width=350;
_loc_4.nav_txt.height=100;
_loc_4.nav_txt.multiline=true;
_loc_4.nav_txt.wordWrap=true;
_loc_4.nav_txt.autoSize=TextFieldAutoSize.LEFT;
_loc_4.nav_txt.selectable=false;
_loc_4.nav_txt.text=param1;
_loc_4.nav_txt.setTextFormat(createTextFormat(para m2, 0, false, HelveticaNeueHvCn, param3, -1.4));
_loc_5=new BitmapData(_loc_4.nav_txt.textWidth+5,_loc_4.nav_t xt.textHeight+5,true,16777215);
_loc_5.draw(_loc_4);
_loc_4.nav_txt.width=_loc_4.nav_txt.textWidth;
_loc_6=new Bitmap(_loc_5);
return _loc_6;
}// end function

public static function setUpText(param1:String):TextField {
var _loc_2:*;
_loc_2 = new TextField();
_loc_2.width=350;
_loc_2.multiline=true;
_loc_2.wordWrap=true;
_loc_2.type=TextFieldType.DYNAMIC;
_loc_2.selectable=false;
_loc_2.text=param1;
return _loc_2;
}// end function

public static function setUpTextBitmapGridText(param1:String, param2:int, param3:int, param4:Number):Bitmap {
var _loc_5:*;
var _loc_6:BitmapData;
var _loc_7:Bitmap;
_loc_5 = new textNavMc();
_loc_5.nav_txt.width=300;
_loc_5.nav_txt.multiline=true;
_loc_5.nav_txt.wordWrap=true;
_loc_5.nav_txt.autoSize=TextFieldAutoSize.LEFT;
_loc_5.nav_txt.selectable=false;
_loc_5.nav_txt.antiAliasType=AntiAliasType.ADVANCE D;
_loc_5.nav_txt.text=param1;
_loc_5.nav_txt.setTextFormat(createTextFormat(para m2, 0, false, HelveticaNeueHvCn, param3, param4));
_loc_5.nav_txt.setTextFormat(createTextFormat(para m2, 10066329, false, HelveticaNeueHvCn, param3, param4), param1.indexOf("
"), param1.length);
_loc_6=new BitmapData(_loc_5.nav_txt.textWidth+5,_loc_5.nav_t xt.textHeight+5,true,16777215);
_loc_6.draw(_loc_5);
_loc_5.nav_txt.width=_loc_5.nav_txt.textWidth;
_loc_7=new Bitmap(_loc_6);
return _loc_7;
}// end function

public static function createInputTextField(param1:String):TextField {
var _loc_2:TextField;
_loc_2 = new TextField();
_loc_2.type=TextFieldType.INPUT;
_loc_2.embedFonts=true;
_loc_2.antiAliasType=AntiAliasType.ADVANCED;
_loc_2.multiline=false;
_loc_2.wordWrap=false;
_loc_2.mouseEnabled=true;
_loc_2.background=true;
_loc_2.backgroundColor=14540253;
_loc_2.text=param1;
return _loc_2;
}// end function

}
}

Anyone know why this is occurring?
Any Help / Suggestion are welcome & appreciated

How To Call A Function First And Create A Delay And Call Another Function
Hi, I am new to actionscript. Is it possible for me to call a function first and call the second function after a short delay.

I try to use this codes. But it didnt work

function a(){
trace("A");
setInterval(b(), 1000);

}

function b(){
trace("b");
}

Call A Function In A Duplicated Movie Clip Form Another Function : (
i have a movie clip on my root name "pl".
on command, it duplicates with instance name as "y0","y1", etc.

here is the method :

function callPL(transmit,receive,addy,level) {

var newName = "y"+_root.x;
duplicateMovieClip("_root.pl",newName,101);
_root[newName]._x = 400;
_root[newName]._y = 400;

_root.[newName].start(transmit,receive,addy,level); //look here
}


there i attempt to call a function of the newly duplicated clip call "start()".
Start() function is written on the first frame of the movieclip like this :


function start(a,b,address,level) {
a.sendAndLoad(address,b,"Post");

this.path = b;

b.onLoad=function(success) {
gotoAndPlay("start");
}
}


however it seems like the function callPL() could not invoke function start() of the new movieClip.I have no idea how is it so.
Even when i trigger it with a onLoad handler it still doesnt work
pls shed some light.

Filling Function Arguments With Array Items, Function.call()
HI!

I have this code but I cannot work out how to fill in function parameters based on an array and it's length, see line 7

ActionScript Code:
import com.robertpenner.easing.Cubic;MovieClip.prototype.framesTimeout = function(func:Function, frames:Number, args:Array) {    var t:Number = 0;    var mc:MovieClip = this.createEmptyMovieClip(String(new Date().getTime()), this.getNextHighestDepth());    mc.onEnterFrame = function() {        if (t == frames) {            func.call(this._parent,args);            delete this.onEnterFrame;            this.removeMovieClip();        } else {            t++;        }    };};MovieClip.prototype.movex = function(x:Number, frames:Number) {    trace(x+" "+frames)    delete this.movex.onEnterFrame;    this.movex.removeMovieClip();    if (!frames) {        frames = 20;    }    var t:Number = 0;    var sx:Number = this._x;    var ax:Number = x-this._x;    var mc:MovieClip = this.createEmptyMovieClip("movex", this.getNextHighestDepth());    mc.onEnterFrame = function() {        if (t == frames) {            delete this.onEnterFrame;            this.removeMovieClip();        } else {            t++;            this._parent._x = Cubic.easeOut(t, sx, ax, frames);        }    };};MovieClip.prototype.otherfunction = function(param1, param2, param3, param4){    trace(param1+" "+param2+" "+param3+" "+param4)}mc.framesTimeout(movex, 50, [100, 50]) mc.framesTimeout(otherfunction, 200, ["asd", 1, 2, 55])

Is it possible to call a function and fill in the parameters based on an array and it's lenth?

My Function Isn't Functioning/Actionscript To Call A Function Flash MX 2004
Hello,

Well in theory I know how to create a function but for some reason I am unable to call it.

Can someone take a look at it and tell me what went wrong. Basically when I go to "a certain page" I want to click on a button and have it go to another page known as "pics" it then will load a jpeg there known as jpeg loader. Now I know it works properly without a functin, but because I am lazy I do not want to write more code than I have to, there are like 300 differnt jpegs I have to load. Thus I need to create a function.

here is my AS


ActionScript Code:
//this is on frame one of my root timeline
//I am trying to call the function "display" on release of my button
 
omnihotelButton.onRelease = display ("J010 Omni Hotel.jpg");
 
 
//this is my function that I set up it is also on my root, but on a different frame
//this function is named display and it goes to the "pics" page and stops
where it then loads a jpeg which is et up as my variable.
//the xscale and the yscale are just setting up my size of the jpeg.
 
function display(jpeg){
    _root.gotoAndStop("pics");
    jpegLoad_mc.loadMovie(jpeg);
    jpegLoad_mc._xscale=90;
    jpegLoad_mc._yscale=90;
}

Inside XmlOnload Function Can Not Call Other Function Directly
I have a question, why the test function can not be called ?
Thanks.

Code:
class testClass {
public function testClass() {
var XMLData:XML = new XML();
XMLData.load("coonfig.xml");
XMLData.onLoad = this.xmlOnLoad;
}
public function xmlOnLoad(success:Boolean) {
if (success) {
// this.test();
test();
}
}
public function test () {
trace("test success");
}
}

Cannot Call Button Function Within Another Event Function
Hopefully someone can help me out with this one. I'm importing XML in order to draw images into an animated scrollbar, and would like to nest a button function within the function urlLoaded as listed below:

import caurina.transitions.*;

var urlCall:URLRequest = new URLRequest("pics/hotel_dreams/hotel_dreams.xml");
var urlLoader:URLLoader = new URLLoader();
var xml:XML;
var xmlList:XMLList;
urlLoader.load(urlCall);
urlLoader.addEventListener(Event.COMPLETE,urlLoade d);

var arrayThumb:Array = new Array();
var photoContainer:Sprite = new Sprite();
addChild(photoContainer);
photoContainer.mask=thumb_holder;


function urlLoaded(event:Event):void {


xml = XML(event.target.data);
xmlList = xml.children();
trace(xmlList.length())
for (var i:int=0; i<xmlList.length(); i++) {
var thumb:Thumbnail = new Thumbnail(xmlList[i].url);
arrayThumb.push(thumb);
arrayThumb[i].y = 67.5;
arrayThumb[i].x = xml.children().x_position[i];
photoContainer.addChild(thumb);
arrayThumb[i].gallery = xml.children().gallery[i];

trace(arrayThumb[i].gallery);


}


}

my hope is to create a button that looks something similar to the following in order to execute an if then statement within the function controlling the visibility of images from the XML based on their gallery property value.

btn_gallery_2.addEventListener(MouseEvent.CLICK, open_gallery_2);
function open_gallery_2(event:MouseEvent) {

if (arrayThumb[i].gallery == 2) {
arrayThumb[i].visible = true
}

}

I have been trying to nest within the urlLoaded function to no avail. By running trace statements I can see that [i] is inaccessible when nested within another function within urlLoaded and when completely outside of the urlLoaded function.

The Thumbnail class referenced is in an .as file that looks like this:

package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;

public class Thumbnail extends Sprite {

private var url:String;
private var loader:Loader;
private var urlRequest:URLRequest;
public var gallery:Number

function Thumbnail(source:String):void {
gallery = 0
url=source;
drawLoader();

}

{
private function drawLoader():void {

urlRequest=new URLRequest(url);
loader=new Loader ;
loader.mouseEnabled=false;
loader.load(urlRequest);
loader.x=-0;
loader.y=-68
;
addChild(loader);

}}}}

I have the suspicion that I am missing something very basic. If anyone out there might be able to give me some insight, then I would be appreciative.

thanks very much

OOP In Flash: Calling A Function W/in A Function Class?
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.
I am trying to get through this code:

ActionScript Code:
House = function(){        this.floors = 4;         this.siding = "Red";         this.outputSiding = function(){            trace(this.siding);         };     };         // create an instance of the House class     myHouse = new House();     myHouse.outputSiding(); // traces "Red"  

Now as it seems to me, I have nearly the same thing (I will condense this to save space):

ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) {    //sets stats used; this works fine :)        //attachMovie and set x/y     _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y});    /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/    statsBox = function(depth)  {        this.depth = depth;        trace(this.depth+newline+'hello');        this.x = enemy._x+130;        this.y = enemy._y-50;        _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y});    };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);

that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.

OOP In Flash: Calling A Function W/in A Function Class?
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.
I am trying to get through this code:

ActionScript Code:
House = function(){        this.floors = 4;         this.siding = "Red";         this.outputSiding = function(){            trace(this.siding);         };     };         // create an instance of the House class     myHouse = new House();     myHouse.outputSiding(); // traces "Red"  

Now as it seems to me, I have nearly the same thing (I will condense this to save space):

ActionScript Code:
//set new character function()character = function (depth, x, y, charType, name, HP, MP) {    //sets stats used; this works fine :)        //attachMovie and set x/y     _root.attachMovie(this.name+"_mc", this.name+"MC", this.depth, {_x:this.x,_y:this.y});    /*this is where I am having trouble; it won't do anything!I have tried tracing to no availalso, can I set the x and y coords somehow with thealready made object x and y? I am tired right now andcan't think of a way but what I have done, which doesnothing as this function won't go!*/    statsBox = function(depth)  {        this.depth = depth;        trace(this.depth+newline+'hello');        this.x = enemy._x+130;        this.y = enemy._y-50;        _root.attachMovie("stats_mc", statsNameMC, this.depth, {_x:this.x,_y:this.y});    };};enemy = new character(30, 350, 200, 'enemy', 'genericName', _root.EHP, _root.EMP);enemy.statsBox(50);

that's it, pretty much. So what's wrong? Maybe I'm too tired for this right now...
thanks.

Constructor Function
Another question:

I want to use on cunstructor function to build several objects but this does not seem possible?

function build(x, y) {
this["val"+x] = y;
}
//
this["testData"+1] = new build(1, 1);
this["testData"+1] = new build(2, 2);
//
trace("fk= "+this["testData"+1].val1);
trace("fk= "+this["testData"+1].val2);
//

I only get a result for the last trace

Any idea how I can get around this one?

Cheers

[OOP]constructor Function
I am trying to learn oop and i am confusing about how to build a constructor function.I mean, i dont understand scopes, what should i put in or out, or even IF i should put something in...
I mean, if i dont have any argument to the new class, so i dont need to put anything inside the constructor function, isnt it?
Thanks in advance

[AS2.0] Constructor Function As Method
Using the constructor as a method to reset an object doens not seem to work in AS2.0 anymore. Example from AS1.0:

Code:
Vector3d.prototype.reset = function (x, y, z) {
this.constructor (x, y, z);
};
How can I rewrite this for AS2.0?

[F8] How Do You Call A Function In A Function In A Class?
I have this class..

class Bob {
function Bob(){
initiate code
}

function loadImages(){
Load images code...
image.onEnterFrame = function(){
if loaded {
this.nextFunction();
}
}
}

function nextFunction(){
do this
}
}


basically, i have a function that loads images.. and i need to have it automatically do another function in that class once the images are loaded..

how do i wait til they're loaded in the class? cause if i put it in "onEnterFrame" , 'this' no longer refers to the class, it refers to the onEnterFrame..

so how do i refer back to the class?
or how do i determine if the images are loaded all in the one class?

Call Function From A Function In A Class?
i havee..

class testClass
{

function testClass()
{
giveFunctions(mc1);
}

function traceIt(tag)
{
trace(tag);
}

function giveFunctions(mc:MovieClip)
{
mc.onRollOver = function()
{
traceIt("SUP");
}
}

}



How do i make the giveFunctions function access the class?

cause it defines a rollover function for an MC.. but in that rollover function, it has to re-reference a different function in the class..

how does that work?

there'll be more variables and it'll be more complex..



I had like,

function giveFunction(mc:MovieClip,tag)
{
mc.sett = this.traceIt;
mc.mca = mc;
mc.tag = tag;

mc.onRollOver = function()
{
this.sett(this.mca,this.tag);
}
}




that works, but it like.. pulls the traceIt function out of the class so it couldn't reference any other variables if it needed to

String With Function Name To Call Function?
hi guys,

it so happened that I have to call some function from XML. What is the best way to do this??

say i have a class "ABC.as" with a function "def()" can I do this:


Code:
var abc:ABC = new ABC();
var strg:String = "def()";

//then i call the function...

abc.strg;
is this going to work?? else is there any solution can let me do something similiar?

thanks!

Call A Function From Inside Another Function?
Hey Guys,

Having a bit of a problem here

Just say this was the case on the main timeline


ActionScript Code:
function topFunction(){
trace("you just called the topFunction")
}

function testFunction(){
function nestedFunction(){
topFunction();
}
}

How the hell do i run the topFunction from inside nestedFunction();. In AS2 if i wanted to reference it i would type _root.topFunction(); but now I don't know how to get to it.

I just need to know how to reference variables and functions from anywhere in my actionscript if i'm in another scope or in another MC.

Thanks guys

[AS]Call A Function After Another Function Ends
Hi,

I have a question: How i make (if it's possible to do this) to call a function after another function is finished. I have 4 function:

ActionScript Code:
function tween1 () {//some tweens}function tween2 () {//some tweens}function tween3 () {//some tweens}function tween4 () {//some tweens}


And i want to play first tween1 and then tween2, when tween2 ends then play tween3 and so on!

It's this possible?

Thanks, btibia.

Pass Function Name To Function And Call
bit stuck on this.

any help much appreciated!


ActionScript Code:
func_1(mc10, 'func_2',[id1, add]);
 
function func_1(tofade, oncompletecall, var){
 
//fade out 'tofade'
//then call oncompletecall(func_2) function..
 
how do i form the call to func_2?
 
}
 
function fun_2(id1, add){
do something...
}

Call A Function Inside A Function
I have a function that attaches a movie clip and names it movieClip_1. I now need the to call the same function again to create movieClip_2 when you click movieClip_1.

Does A Subclass's Constructor Automatically Call It's Superclass Constructor?
Hi guys

I have 2 classes:


Code:

class Player{

function Player()
{
super()
directionStack = new DirectionStacker()
}
}
and


Code:

class DirectionStack extends Player{

function DirectionStack()
{ }

}
does an infinite loop happen there? What I read in the Flash help (that comes with the software) is that you need to call super() if you want to call your superclass's constructor. But in this code, am I automatically going to the superclass's constructor? I'm getting this message:


Quote:




256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.

Function Under Condition
Hi everybody,
could you help me with this?:

On root timeline I have a button with this script:

Code:
on (rollOver) {_root.fast = true}
on (rollOut) {_root.fast = false}

and one movie clip with motion tween inside.

I would like to control speed of that tween with described button. Above every frame of tween inside mc is this script:


Code:
if (_root.fast = true) {
function timelineFaster() {
nextFrame();
updateAfterEvent();
}
var tweenFaster:Number = setInterval(timelineFaster, 42);
} else {
function timelineFaster() {
nextFrame();
updateAfterEvent();
}
clearInterval(tweenFaster);
play();
}


This function works perfectlly standalone, but with condition doesn't. Have any idea? Thanks for anything in advance.

chulimanga

[F8] Calling A Function Froma Function
Please excuse my ignorance, but can i call a function from a different function. I'm not sure how to do it.

eg:
myBut.onPress = function ()
{
_root.currentimage=1;
_root.crumb.titles="/fashion&lifestyle";
_root.loadLeft._visible=0;
FashStrip.mc01._alpha = 60;
}

how do i integrate this into the above function?:
function fadeOut()
{
extendTween = new TweenExtended(_root.loadLeft.fashThumb,["_alpha"],
easingType4,[_root.loadLeft.fashThumb._alpha],[0],1,true);
}

i know i could put it straight in the button function but i want to reuse the fadeOut function again many times!!! (just learning to keep my code nice and neat)

Rat

Calling Function From Within A Nested Function
Hi guys,

I current have this piece of code:


Code:

var parentObj:Object = this;

this.form.submit.onRelease = function() {
parentObj.processingIn();
}

function processingAnimationIn():Void{
//DO STUFF
}
But I can't get this to work. Does anyone know what's going on?

Thanks!

Calling A Function Inside Another Function
Hi All,

I've set up two functions (friendsClick and policyLink) I would like to use everything inside of friendsClick inside of policyLink but I'm not sure how to go about doing it. I get the following error:
1136: Incorrect number of arguments. Expected 1.

My code looks similar to:


Code:
function policyLink(e:MouseEvent){
friendsClick();
"all my other info here"
}
I can just copy everything from the friendsClick function and paste, but I'm trying to limit my amount of repetitive code (I'm trying to get better at that). Please Help.

Calling A Function Inside Another Function
Hi i've created some functions that run when diffrenent buttons are pressed, and they work fine, but i want something else to do the same thing when any of the buttons are pressed, i thought the easiest way to do it was to create a function and call it each time one of the buttons are pressed. but what is the code to run the function??

all the code is on the main timeline..

i've wrote this and it doesn't work....

the function i want to run is:


brentGandS = function (){
_root.menu_mc.brent_mc.tween("_width",200,5,"easeoutelastic")
}


and the on press function is:

menu_mc.contact_btn.onPress = function() {
window_mc.resizeTo(250, 350, speed, "easeoutelastic", onEnda);
brentGandS
};

any ideas????????

Class Constructor Function - Please Explain
I consider myself an intermediate Flash coder, and I've been teaching myself about classes. I understand how they work, except for one thing: Constructor Functions.

I've read the Flash documentation on what they are and what their function is. This, I do understant. I just don't understand how they work. Take, for example, the following code that is offered as an example by the Flash documentation:


Code:
class User {
// private instance variables
private var __username:String;
private var __password:String;

// constructor statement
public function User(p_username:String, p_password:String) {
this.__username = p_username;
this.__password = p_password;
}

public function get username():String {
return this.__username;
}
public function set username(value:String):Void {
this.__username = value;
}

public function get password():String {
return this.__password;
}
public function set password(value:String):Void {
this.__password = value;
}
}


The thing that I don't understand is: how is the constructor function calling the setter function without explicitly calling it? If it is callling the setter function, how is it doing that? All that I see is that it is setting a the variables "__username" and "__password".

You'd think that it would have to be written like so:


Code:

// constructor statement
public function User(p_username:String, p_password:String) {
username(p_username);
password(p_password);
}


Can annyone help me bridge the gap here?

Thanks!

Class Constructor Function - Please Explain
I consider myself an intermediate Flash coder, and I've been teaching myself about classes. I understand how they work, except for one thing: Constructor Functions.

I've read the Flash documentation on what they are and what their function is. This, I do understant. I just don't understand how they work. Take, for example, the following code that is offered as an example by the Flash documentation:


Code:

class User {
// private instance variables
private var __username:String;
private var __password:String;

// constructor statement
public function User(p_username:String, p_password:String) {
this.__username = p_username;
this.__password = p_password;
}

public function get username():String {
return this.__username;
}
public function set username(value:String):Void {
this.__username = value;
}

public function get password():String {
return this.__password;
}
public function set password(value:String):Void {
this.__password = value;
}
}
The thing that I don't understand is: how is the constructor function calling the setter function without explicitly calling it? If it is callling the setter function, how is it doing that? All that I see is that it is setting the variables "__username" and "__password".

You'd think that it would have to be written like so:


Code:

// constructor statement
public function User(p_username:String, p_password:String) {
username(p_username);
password(p_password);
}
Can annyone help me bridge the gap here?

Thanks!

Constructor Function Cannot Access Stage
inside a class's constructor function I had

ActionScript Code:
t0_txt.stage.focus = t0_txt
t0_txt.setSelection(0, 0)

but from constructor function stage is not accessible so I used setTimeout


ActionScript Code:
public function contactform()
        {
    setTimeout(focusfirst, 10)
        }
    public function focusfirst():void{
            t0_txt.stage.focus = t0_txt
            t0_txt.setSelection(0, 0)
    }

I feel that setTimeout is not a good saolution and may cause problems...
how are these type of things usually done?

Having Problems With LoadMovie In My Constructor Function?
First time poster, long time lurker, heh. Majority of the time I've been able to find the solutions to my problems by simply searching through the forums or CyanBlue's 5000th post (saved my ass lots of times, so thank you), however I've been fighting with and searching these forums for answers for the last 3 days and haven't been able to find a solution. Hopefully someone here can help me.

I'm running into a problem loading jpegs in dynamically through an xml attribute. I have a clip in my library named "boxx", which attaches to the stage fine through my constructor function. The problem I'm running into is when I try to load the jpeg into each instance of "boxx". The path passes fine to the constructor function when I trace it, and if I load the jpeg into an instance just placed on my stage, it works fine. For some reason though it seems that when I attach the clips to the stage dynamically, it erases the blank holder clip ("playerPic") I placed entirely? Or just doesn't recognize it??! I checked my paths many times, so I'm just completely lost as to what is wrong. Any help you guys might provide would be greatly appreciated. Thank you.

This is my xml code:

HTML Code:
<?xml version = "1.0" encoding = "UTF-8"?>
<team>
<player picture="players/pic.jpg" number="14" name="David Ronnie" playerUrl="91543" />
<player picture="players/pic1.jpg" number="15" name="Brad Kronewitt" playerUrl="91653" />
<player picture="players/pic2.jpg" number="16" name="Heiko Ryll" playerUrl="91543" />
<player picture="players/pic3.jpg" number="17" name="Jenkin Yeung" playerUrl="92584" />
<player picture="players/pic4.jpg" number="14" name="James Huynh" playerUrl="96532" />
<player picture="players/pic5.jpg" number="34" name="Dana Schmidt" playerUrl="91543" />
<player picture="players/pic6.jpg" number="25" name="Erin English" playerUrl="98756" />
<player picture="players/pic7.jpg" number="14" name="Kara Lavallee" playerUrl="95681" />
<player picture="players/pic8.jpg" number="14" name="Mandey Bonn" playerUrl="59813" />
<player picture="players/pic9.jpg" number="16" name="Mark Prosser" playerUrl="56847" />
<player picture="players/pic10.jpg" number="15" name="David Ronnie" playerUrl="89456" />
<player picture="players/pic20.jpg" number="99" name="Fluffy Farfignoogen" playerUrl="91543" />
</team>
I'm using the following actionscript code:

PHP Code:



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              xml ****
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

playersXML = new XML();
playersXML.ignoreWhite = true;
playersXML.onLoad = function(){
    xmlParse(this);
};
playersXML.load("players.xml");
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          xml parser function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function xmlParse(xmlFile){
    _root.playerNodes = xmlFile.firstChild.childNodes;
    _root.createEmptyMovieClip("holder",2);
    _root.holder._x = -130;
    _root.holder._y = 150;
    for(i=0;i<_root.playerNodes.length;i++){
        _root.holder.attachMovie("boxx","boxx_mc"+i,i,new UberButton(i,_root.playerNodes[i].attributes.name,_root.playerNodes[i].attributes.number,_root.playerNodes[i].attributes.picture,_root.playerNodes[i].attributes.playerUrl));
        _root.trackArray[i] = "boxx_mc"+i;
    }
    _root.holder.onEnterFrame = function(){
        if(_root.transit == true){
            if(_root.speed == -60){
                this._x += ((this._x-75)/_root.speed)*0.98;
            } else{
                spot = -(this._width-740);
                this._x += ((spot - this._x)/_root.speed)*0.98
            }
        }
    }
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    UberButton Construct Funct.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function UberButton(xVal, name, number, pic, purl){
    this.pInfo = "#"+number+ " "+name;
    this.url = url;
    this._x = (xVal*75);
    this._y = 0;
    this.playerPic.loadMovie(pic);
    this.onRollOver = function(){ 
        this.gotoAndPlay("roll");
        _root.rrcursor2.nameBar._alpha = 100;
        _root.playerInfo = this.pInfo;
    };
    this.onRollOut = function(){ 
        this.gotoAndPlay("rollOut");
        _root.rrcursor2.nameBar._alpha = 0;
        _root.playerInfo = "";
    };
    this.onRelease = function(){ 
        this.gotoAndPlay("rollOut");
        trace("?p="+purl);
    };
    this.onReleaseOutside = function(){ 
        this.gotoAndPlay("rollOut");
        _root.rrcursor2.nameBar._alpha = 0;
        _root.playerInfo = "";
    };
    this.onPress = function(){ 
        this.gotoAndStop("hit");
    };





Once again, thanks for any help you guys might provide, because I'm completely lost as to why it won't recognize it, I even tried createEmptyMovieClip within the boxx instances on the fly, but still to no avail.

[edit]
Added a stripped down version in an attachment with some sample pics and xml file as well if anybody wants. Thanks again.
[/edit]

2d Arrays Inside Constructor Function
I have a problem that i think i can solve if i create a 2d array based on another two arrays
Im trying something like that

PHP Code:



var my2dAr:Array = new Array();var i = ar1.length;var j = ar2.length;while(i--){my2dAr[i] = new Array();while(j--){my2dAr[i][j] = false;}} 




inside the constructor function of myclass but it seems that it makes the script too slow and unresponsible
So is there any way to make this 2d array inside this constructor function?OR a way to fake it?
Thanks

Accessing Constructor Variable From A Function?
So, I'm trying to write a generic video player in AS3. I actually had it working perfectly when writing it on the stage in a frame. (so much easier!) Then I decided to convert it to a document class, that being a better coding practice and all.

My main issue now is this part in the constructor:


Code:
// Create net connection and stream.
var conn:NetConnection = new NetConnection();
conn.connect(null);

var stream:NetStream = new NetStream(conn);
stream.play(mfile);

var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
stream.client = metaListener;

// Sound
var st:SoundTransform = new SoundTransform();
stream.soundTransform = st;

// Video
var video:Video = new Video();
video.attachNetStream(stream);
This is followed by a bunch of eventListeners. Several functions called by the eventListeners reference conn, stream and str, so the result is a whole bunch of 1120: Access of undefined property conn. errors. This is where I need the variables to go global.

I did attempt to move the variables above out of the function, but that gave me the following output, which leaves me even more lost.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at src.videoPlayer::videoPlayer()

Any help is deeply appreciated!

Function Inside/outside An If Condition
Hi,

I noticed that defining a funciton inside an if condition seems to act
different than one defined before that. I tried to use an setInterval on
a function, both in- and outside the if conditon.

// this one does nothing
if (1){
function globalLoop(){
trace("globalLoop")
}
lv1 = setInterval(globalLoop,100)
}



// this one does loop
function globalLoop(){
trace("globalLoop")
}
if (1){
lv1 = setInterval(globalLoop,100)
}


Where is the difference, how does this behavior explain?

Killing A Function On Certain Condition?
Ive always wondered how to do this because functions rock but they cause me so much pain due to how I use them.

For example. Say we're driving a ship at a constant rate of 45 miles per second:


ActionScript Code:
function milesTraveled() {    myMiles += 45;    if (myMiles>=4500) {        myMiles = 4500;        trace("reached destination");        refillGas();    }}setInterval(milesTraveled, 1000);
Now as you can see it runs the function refilllGas(); but it -keeps- on running refillGas(); due to the setInterval that runs the main function everysecond.

Any way to cut the function milesTraveled for good once I hit a certain condition?

Can't Call Function Created Via Eval Using ExternalInterface.call
I have created a flash movie that acts as an MP3 player. Using ExternalInterface, I pass an array containing cue points in the song to the flash move so that it makes a callback to javascript when it hits certain points in the song. Since I want to deal with these callbacks differently for each song, I have made it so that I can dyanmically change the function that is called from Flash (to Javascript). Here is the code for that piece:

ExternalInterface.addCallback("setCuePointFunction ToCall", this, setCuePointFunctionToCall);

var cuePointFunctionToCall:String='';
var intCurrentCuePoint:Number=0;

function setCuePointFunctionToCall(strFunctionName){
_root.cuePointFunctionToCall=strFunctionName;
}

function reportToJavascript_CuePoint(intCuePointID:Number){
ExternalInterface.call(_root.cuePointFunctionToCal l, intCuePointID);
_root.intCurrentCuePoint++;
}

This works perfectly as long as the function that cuePointFunctionToCall refers to is defined in a script block on the HTML page. However, this project is an AJAX-style thing, and I need to be able to define the function that is triggered on a cue point in code that is dynamically executed at run-time via an "eval' call.

Here's the code that talks to actionscript. This appears in a script block on the main page (not via eval).

function setCuePointFunctionToCall(strFunctionName) {
thisMovie("PushPuppets_Media_Center").setCuePointF unctionToCall(strFunctionName);
//alert(strURL);
}

function thisMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}

Here's the code that is dyamically being executed via an eval statement in javascript:

setCuePointFunctionToCall("cuePointNew");

function cuePointNew(lngCuePointID) {
alert('New function, cue point: ' + lngCuePointID);
}

This does not work. But if I copy the above function block to the main page (not in the code that is executed via an eval) it does work. I am certain that setCuePointFunctionToCall is being executed properly via the eval - it is definitely changing the function that actionscript will call. This is apparent since it is calling the right function when the function is declared on the HTML page (not in the AJAX-style eval call). So I'm guessing that this has something to do with the scope in which eval operates.

I encountered a very similar problem when I tried redefining a function in the eval call that was already defined on the main page. It just didn't take.

Please let me know if you have any suggestions.

Thanks,

Erich

Calling A Function, External To The Calling Class
hello to everyone, who looks at this post
So there's a class, that needs to call/access an external function.
'External' (imho) in this case would be any function, declared outside of the class.
How is it possible to:
1) call a function declared in the main timeline.
2) call a function in another class (i suppose, the only way of doing it is by importing the class having this function into the calling class?)

Can't Call A Function Within A Function?
Here's an example of my code:


Code:
function getName():void
{
var name:String = "George";
displayName(name);
}
function displayName(n:String):void
{
name_txt.text = n;
}
I get runtime error #1120 because of line "displayName(name);"

Is this something you can't do in AS3? If so, what is the proper way?

Also, this COMPLETELY off subject, but how come my post is being dispalyed as Code instead of Actionscript Code?

Thanks in advance.
E

Function After Function Call
I want to place this function at the bottom of my code

ActionScript Code:
function textbox():void
    {
        var txtFld:TextField = new TextField();
        txtFld.x = 420;
        txtFld.y = 220;
        txtFld.width = 200;
        for (var i:Number = 0; i < 10; i++)
            txtFld.appendText( i);
        addChild(txtFld);      
    }
, after the function call:

ActionScript Code:
textbox();

However I am geting errors since the function call is first, how can I get the code to work ?

[FMX] Function Call From Outside Function
issue: i have an mc called mcTextEffects attached to the stage:
attachMovie("mcTextEffects", "mcTextEffects", getNextHighestDepth());

inside this mc, there is function which accepts following parameters:
function displayText(sText:String, nEff:Number){
.....
}

this function animates string-input "sText" in some way according to "nEff"..

(1) mcTextEffects is attached in _root timeline
(2) function displayText is contained within mcTextEffects.

I want to call this funcion from _root timeline after mcTextEffects has been attached. I tried this way:
mcTextEffects.displayText("hallooo", 2);

doesnt work.

I found out that this way it works:
var nIntervall:Number=setInterval(animate, 0); // delay can be zero!!
function animate():Void{
clearInterval(nIntervall);
mcTextEffects.displayText("hallooo", 2);
};

I would like to understand what is going on, and why i cant access the function through simply calling _root.mc.function() as mentioned above.

Any help apprecciated

Function Call From Function
I have the following problem:

In one of my objects I have declared several functions. One of the functions is calling another several times. It looks like this:

function1 {
...code...
call of function2
...code...
call of function2
...code...
call of function2
...code...
}

function2 {
...code...
}

Now what is strange to me is that the program somehow "collects" the function calls and waits with the execution until function1 is completed. Is it possible to force AS to execute the second function immediately when it's called?

Thanks for your help...

Jan

Calling Function For Mc From Within Other Function?
Hello, been taring my hair out over this little problem. I'm trying to call below function for a movie clip from within an onRelease function on another movie clip.

The full extent of my problem is that i want movie clips to fade in on the stage when i press a movieClip button. The code below works fine if i call it from an onClipEvent handler on the actuall movie clip, but I'd like to control when It happens from somewhere else.


Code:
function fadein(clip, tAlpha) {
clip._alpha += (tAlpha-clip._alpha)/15;
if(Math.abs(clip._alpha-tAlpha) < 1) clip._alpha = Math.ceil(tAlpha);
}
i've tried attachMovie from teh library, but still if just after that try to call this function the movie clip only snaps in on the stage and won't use the function.


Code:
this.onRelease = function() {
homePage._visible = false;
_root.attachMovie("testePage", "testemonialPage", 3);
testemonialPage.onEnterFrame = function(){
fadein(this, 100)
}
}
but no go with this.... i'm sure it's a simple task for someone more apt at AS. big thanks for any help! cheers, david

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