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.
FlashKit > Flash Help > Flash ActionScript
Posted on: 08-01-2001, 09:13 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
How To Call Function In _root?
looks like this is not working.
I have one function in _root, so I need to call it from one MC using button..
when I try to do that with
on (release){
_root.compareArrays(arr1, arr2);
}
it`s not working.. if I put that button in _root it works just fine
so what`s my problem?
tnx!
Calling Function In MC From _root
Was hoping someone could help me out with this...it seems like such a simple thing.
I am just trying to call a function with in a movieclip at run time from the root timeline.
For example:
var theFunction:Function = function(){
myMovie_mc.myFunction();
}
theFunction();
then inside my movieclip it is just a simple
var myFunction:Function = function(){
trace ("Hello");
}
If I put this function on the root time line and call it it works fine. Also, if I call this function from the root timeline using a button and onRelease it also works fine! Just not when I am calling it at runtime?! Is it a timing issue where the movieclip functions are not initiated yet?
Calling A Function In An MC From _root
Hey everyone,
I was wondering, is it possible to call a function in a MC from the _root of the movie?
I have an MC called timer, linked aswith a function in it,
Code:
testFunc = function(){
trace("It Worked!");
}
On the _root in the first frame I have this,
Code:
_root.attachMovie("timer","t",5);
_root.t.testFunc();
This don't work, what am I doing wrong and how can I get it working?
Thanks in advance for helpful replys.
_root.function Not Calling?
Hi!
Please, have a look on the following code. As you can see, it defines a function in the main timeline:
PHP Code:
function movf(){ //does something;}
Then I load a movie into that main timeline, and from within that movie i call the function:
PHP Code:
mc.onRelease = function(){ _root.movf();}
But it doesnt work. Why?!
Loaded Swf Won't Call Function In _root Movie
Morning / evening! Hope people are well....
Problem: I thought functions were global? Why won't my SWF talk to my main movie?
I load a SWF into a container on my main timeline. I click on a 'button' within my loaded SWF, the 'button' does everything it's meant to internally, but doesn't call the maintimeline function. I thought the CONTAINER would take on all of the properties of the LOADED SWF, so scoping wise can't I just code the call to the function as I normally would.
Any advice would be much appreciated.
Thanks!
Calling A Function In _root From An External Swf's Button?
Is it possible to call and execute a function from a button (or mc) contained within a loaded external swf? I have tried with no success.
I'll try to explain this the best i can.
Basically, what i want to do is have a button that's contained in the "contact us" section that will open up a guestbook for visitor to leave comments etc. But on(release) of the button, i want to start the closing page transition for the contact page, which will unload the swf when it ends, and then load the guestbook into my container clip.
So in order for it to work properly and preload, i would assume that i have to call the function that my main menu buttons use to check if the page is already loaded, and if not, loadMovie() and start preloader.
Is this possible or not?
OH..... and one other question if anyone has an idea.... Each of the site section use a lot of the same function()s, so i was wondering if i created an external AS file that contained all of the functions that I used in more than one swf, can i save myself the time of writing the code into each and call the function()s contained within the external file?
THANKS IN ADVANCE!!!!
Calling An Instance In A Function
I'm trying to write a function that will adjust the scale of various movie clips. Here's what I've got so far, I think I'm not calling the movie clip instance properly...
Code:
function workTheRollover(movieName){
movieName._xscale = 110;
movieName._yscale = 110;
}
m_cottonCandy.onRollOver = function(){
trace("Rolled over "+this._name);
workTheRollover(this._name);
}
Can We Call A Built-in Function Like This _root[buttonName].onPress();
In my application, every thing should work with key board keys. So, when I press left arrow it should act like I pressed previous button.
On an empty movie clip I have following code.Is it ok or we can not execute commands by code? Any ideas.
onClipEvent (enterFrame) {
if(Key.isDown(Key.LEFT)) {
trace("left");
_root[previous].onPress();
}
}
How To Call GotoAndPlay Function Activated In _root From An External MC With AS3?
Dear all,
I am newbie in AS3. I have a problem:
parent movieclip:
var ldr:Loader = new Loader();
ldr.mask = rect;
var url:String = "yes/color_match.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
--> the external MC is color_match.swf
Problem is: how can I call _root to gotoAndPlay(frame) in the child (which is color_match)?
I tried and prompt error: color_match.as, Line 87
1061: Call to a possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObjectContainer.
Anyone can help me? It takes me quite lots of time for this stupid code.
Thanks,
michoux
Calling Function On Movie Instance?
Say I have a movie clip called viewer.
Inside "viewer" I have a function defined in frame 1:
function foo(){
trace("foo called");
}
Then I do this:
this.attachMovie("Viewer", "window", 0);
window._x = 100;
window._y = 100;
window.foo(); //this doesn't work
Why window.foo() doesn't work?
The "viewer" movie is shown, but the foo
function is not called.
I think I am missing some basic concepts of flash...
Thanks.
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!
How To Call A Function On Main Stage From Inside A Symbol Instance
Hi everyone,
I have a silly AS3 question for you.. though I've looked and can't find the answer.. maybe it's too obvious!!
How do I call a global function which I defined in my main stage from inside an instance of a symbol, which sits on the main stage?
ie the function in the main stage:
function doSomething(x:String):void
{
trace ("woohoo");
}
and inside the symbol:
function callDoSomething(:xString):void
{
doSomething(x);
}
Do I have to... create a default document class.. or a custom one perhaps? do I have to put this.parent or this.stage in front of doSomething(x)??? I dunno...
Thanks a lot!
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.
[F8] [AS2] Access An Instance Variable From Within A Function Within Another Function
So here is the scenario that has completely stumped me. I have a class, within the class a function and within that function an xml onload handler. So herein lies the problem, I need to store the array of values that I receive from the XML into an instance variable belonging to the class. How can this be achieved?
To illustrate:
Class A {private var values:Array;public function getValues():Void{Xml sendandload code here.xmlReply.onLoad = function(){iterate through xml code and generate array of values.Store this array back into values belonging to class A}}}
using the variable straight up doesn't work.
if I use "this" it refers to the onload function, not the class.
i tried creating another class method called setValue and calling this.setValue(arr) and setValue(arr), but neither of those work.
i even tried combinations of _parent and this, still no go.
The only way I can get it to work is to make reference to _root.class.value, but this is not solid code and is very impracticale, especially if what calls the class doesn't happen to be in the root of the file.
Any ideas would be appreciated.
[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.
[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????????
[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;
}
}
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
Access Property/function Of Instance From Inside Another Instance
Might be something really obvious, but I'm still trying to get my head round as3...
I need to call up a property and function of another instance of the same class, similar as in as2 (called from within "_root.instance_mc1"):
ActionScript Code:
_root.instance_mc2.someNumber = 0;
_root.instance_mc2.someFunction();
Now in AS3 I can access the object (extending sprite) itself (and inherited properties like x) by using:
ActionScript Code:
this.parent.getChildByName("row2").x
but if i try to access public variables/functions from that object (this.parent.getChildByName("row2").someNumber) I get Error 1119: Access of possibly undefined property someNumber through a reference with static type flash.displayisplayObject.
Anyone know how I can get this to work?
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
Calling A Function From A Function
How can I get a function to call another function? I simply cannot get it to work:
ActionScript Code:
function displayMenu() {clearMenu}
This is a cut down version of my code for clarification purposes - it doesn't work either.
Does it have to be in an "on" handler (onClipEvent or onEnterFrame for example)? 'cause I just want it to run the other function automatically without the user having to do anything or the movie having to go to any particular frame. blah
Calling A Function From Within Function
Is there any way to call a function from within a function?
***************************************************
Here is the Function I am calling from:
SET.onRelease = function() {
in1_txt.text = "C";
in2_txt.text = "F";
in3_txt.text = "G";
OUT1.text = "C";
OUT2.text = "F";
OUT3.text = "G";
varKeyShift = 0;
this._parent.varShow = "SET.onRelease";
Output_Key(); // Here is the Function call
};
****************************************
Here is the function I am calling:
function Output_Key() {
this._parent.var1 = 1;
}
*******************************************
I have an Input Text with Variable Name "var1"
but var1 shows no value when clip is run
[AS2] Call A Custom Function From Another Custom Function's Parameter?
Hello there!
This is my second post in this forum
Here is the problem:
I want to call a function from another function's parameter but I don't know how and don't know if it is possible.
I've considered this as a solution but it didn't worked.
Code:
function myFunc(target_mc:MovieClip, nX:Number, nY:Number, cFunc:Function) {
target_mc._x += nX;
targen_mc._y += nY;
target_mc.onPress = cFunc;
}
function go() {
//some code goes here
}
myFunc(my_mc,50,50,go);
I hope you get the idea.
Sorry for my English
_root.onEnterFrame = Function() HELP
hi,
am using _root.onEnterFrame = function() to run some postion changes
and to get a timer going.. thing is i want the timer to start from 0
each time the function gets called as the function counts till 20
then does something else..if it carrys on the function wont work the
next time its passed... so basically is there any way of stopping the
enterframe function.. below is my code..
function back () {
if (_root.inPos == true) {
corn1.X = 87.25
corn1.Y = 52.5
corn2.X = 95.85
corn2.Y = 52.6
corn4.X = 95.85
corn4.Y = 60.85
corn3.X = 87.25
corn3.Y = 61
inPos = false;
_root.onEnterFrame = function() {
time = time+1;
if (time == 20) {
this.go()
}
}
}
}
anyone with any ideas ??
_root.onMouseDown = Function () { ?
_root.onMouseDown = function () { ?
I am trying to create a sertin game, and I need this one part that I cant figure out the action script..
Ofcourse as the title says:
_root.onMouseDown = function () {
addGB();
}
function addGB () {
// this is were I need help, I need it were once I press down on my mouse a new box appears RIGHT were I clicked.
}
If any one knows or understands me let me know.
Help would be appriciated.
-Schlimm
Function And _root Objects
Im having trouble using a function to change a value of a text field on the stage.
Here's a simplified version of what im doing
ActionScript Code:
function ChangeTxt (NewTxt, Location){
Location = NewTxt
}
ChangeTxt ("MyNewText", _root.TextArea1)
I want to update the variable TextArea1 with NewTxt using the above function but it doesn't seem to be working
I think its because its not accepting _root.TextArea1 as the function variable
Can any one help?
|