ActionScript 3.0 :: Pass The Scope Of One Class To The Function Of Another
Oct 5, 2011
[Code]...
Specifies the value of thisObject to be used within any function that ActionScript calls. This method also specifies the parameters to be passed to any called function. Because apply() is a method of the Function class, it is also a method of every Function object in ActionScript. i don't get how "thisObject" is accessible from within the function invoked with it's apply method i'm trying to pass the scope of one class to the function of another so that the keyword "this" in the target function refers to the passed scope or am i misunderstanding the apply() method? it appears to behave differently between as2.0 and as3.0 as well, try this example code from the adobe docs
[Code]....
View 3 Replies
Similar Posts:
Feb 21, 2009
I have 2 class. Main class and a subclass (being an image loader).When the subclass has finished loading I want it to access a timer function in the mainclass.Code: Select all1)mainclass |> subClass.loadMe();2) When subclass load finished.3)Subclass |> mainclass.startTimer();This i dont know how to do.
View 2 Replies
Feb 7, 2009
I have an object and would like to call a function from it, which the way I am trying to do it, does not seem to work. Here is what I have:
Code:
private function setTimer():Void
{
[code]......
View 0 Replies
Sep 10, 2009
I ran into a problem today. Since I wanna pass a class name as a function parameter. In that function I wanna make instances of that class,
View 3 Replies
Mar 14, 2009
I have recently moved from AS2 to AS3 and I am finding the transition fairly easy, however I do have a few questions, some of which may not have been possible with AS2 but I would like to achieve them in AS3
1. Is it possible to pass the name of a class as an argument in a function and then use it to create a new instance. e.g [code]
2. Carrying on from the previous question, if a class can infact be passed, can I specifying a variable type for the argument so that only classes and not instances will be accepted?
3. I have three class files that all inherit some functions and variable from another class called Ship. Is it possible to specifying a variable type so that the variable can only hold instances of classes that are inherited from the Ship class?
View 6 Replies
Aug 15, 2011
I've got a main.as that loads SWF to the stage. the loaded SWF seppoused to pass a link to the main.as and trigger a javascript function to popUp that photo from that link.
I know there are two ways:
((root as MovieClip).parent.parent as Object).somefunction(parameters);
and to dispatch an event. inorder to pass parameters throug the event i need to extend it with another class.
isnt the (root as... ) more efficient if all i need is to pass a link?
View 7 Replies
May 12, 2011
I have a class file defined in my package as MyGlobals.as.[code] (I have tried adding/removing "static" and "dynamic" to no effect.)I am trying to call a touch event from the main timeline in this way:myObject.addEventListener(TouchEvent.TOUCH_BEGIN, MyGlobals.myFunctionName);(I have tried removing the class name to no effect.)When I compile I get the error 1046: Type was not found or was not a compile-time constant: TouchEvent. This error occurs on function definitions in the class file.What syntax/concept am I getting wrong? The functions were working fine when I was using constants in the timeline, but I need to be able to reuse these functions over and over again, so I wanted them to be able to take touch event variables so that I didn't have to write a different function for every touch event.I tried googling "error 1046" but I can't find anything useful.
View 3 Replies
Nov 20, 2008
I have a movieClip named MC, and it's enabled with action script, with the class name MC_Rectangle and a Stage.I override the MC_Rectangle class file in a mc_rectangle.as external file.here is the code:
package{
import flash.display.*;
import flash.events.*;[ code].....
I have new a object in the main stage var
mc_rect:MC_Rectangle = new MC_Rectangle()
in main stage:
1. how can i access the variable "sequence" in "mc_rect"
2. how can i pass parametre from main stage to mc_rect via function setSequence(data:int)?
3. how can i call the function in addSequence() in mc_rect.
in asp.net, i usually use mc_rect.sequenct,mc_rect.setSequence(data), mc_rect.addSequence() to achieve my goals......btw, can function in mc_rect return out result to main stage?
View 1 Replies
Jul 1, 2004
I add this actionscript code on the first frame. Variables are loaded but. The question is below the code.
[Code]...
View 2 Replies
Jul 3, 2007
Here is the script:
Code:
function delay(pFunc:Function):Void {
this.onEnterFrame = function() {
pFunc(param);[code]....
It's stripped down to reproduce my issue.I want to change the scope of the event, so that when test is called, it traces "_level0 instead of "[object Object". I was thinking Delegate.create() would be the way to go, but I can't figure out how to get that to work within the scope of this function.
View 4 Replies
May 19, 2005
I'm having a problem calling a function from a different level.I have my main movie 'Mymovie.swf' in which I add a level(with loadMovie) with this code:
loadMovie("MyNewMovie.swf", "_level1");
On a button in MyNewMovie.swf, I try to call a function in 'Mymovie.swf', by doing:
on(release){
_root.MyFunction();
// or even: _level0.MyFunction();
}
View 2 Replies
Aug 24, 2009
Normally when creating small apps, i create a small object something like this.
Code:
//Example
var theApp:Function = function(){
[code].....
View 0 Replies
Jun 9, 2006
Take a look at this code:
Code:
import mx.utils.Delegate;
class Test
{
[code]....
Well... Doesnt work at all... In the class, there isnt a instance of i, so, how may i access this property inside a class function? But i still have an way to access the class.
I could do this way:
Code:
class Test
{
function Test(mc:MovieClip)
{
[code]....
But this way, doesn't sounds good
View 3 Replies
Feb 18, 2005
I have this extremely odd problem. OK to start off I have an MC in my library with the linkage identifier "Interface" and the AS2 class "Player" (both without "" of course). Now, my player class looks like this.
[Code]...
View 7 Replies
Apr 2, 2010
I have a Debug class I've written, and I'd like to include a static trace() method in there, unfortunately I have no idea how to then access global / top level trace as effectively I've blocked it with the local static scope.[code]
View 4 Replies
Jul 14, 2010
I have the standard dragWindow function in an app I am building:
private function dragWindow(evt:MouseEvent):void
{
stage.nativeWindow.startMove();
}
I want to limit the "scope" of this function such that it is not enabled within specified components, e.g. datagrids, scrollable lists, etc.
View 0 Replies
Sep 14, 2010
What is the scope of a class created in Flash? If you create a class on the main timeline, can you use it anywhere in your project? If you use your class in a a movieclip, can you use that class outside of the movie clip?
View 3 Replies
Feb 19, 2012
I recently completed a tic-tac-toe game in AS3, using some simple function-based code I had written in C many years ago.Now I'm on a quest to do it the "right way" using OOP techniques and best practices.Everything is now divided into neat little packages, it looks pretty, and the last part of my journey is to get all the little buggers to communicate with each other.I want to move the code which holds the game state from my main to it's own class in com.okaygraphics.model.GameState.The problem is nearly every other package gets and sets these game state properties.I'm trying to figure out the simplest way to encapsulate this stuff, while still allowing my other classes to access it.
1) Do I need a constructor? I mean, my program will never have more than one GameState. If I should call my getters/setters as instance methods, how do I get each other class to reference the SAME instance from their respective packages?
2) Do I even need getters and setters? Perhaps the class could just have 3 public properties? If so, how would I acheive the proper scope with regard to my other classes?
3) Should I assign everything to the class itself using the static keyword? If so, how would I implement and use those static methods?
4) Is this a mistake? Did I totally just program myself into a corner?
View 3 Replies
Aug 10, 2006
How do I fix this? With this code in my class:
function moveDelay():Void {
myInterval = setInterval(this.movePoints, delay);
}
I lose scope when it calls the function. "this" becomes undefined.
View 1 Replies
Aug 12, 2008
I have 3 files.
main.fla
PHP Code:
import classes.LevelObj;
var newLevel:LevelObj = new LevelObj();
var levelListener:Object = new Object();
levelListener.onLoaded = function(oEvent:Object) {
[Code] .....
Now this runs great but in the loadLevel function of LevelObj.as, when I receive the event from the GBXML class that it has finished loading I want to call another function within the same class (LevelObj) to continue with further processing the XML data. What I make of it, is that I am still within the scope of the myListener object. Should I use a Delegate function here to get to the function within the LevelObj scope?And how about properties from the LevelObj scope? When doing a simple trace of some testVar I get undefined. Logical ofcourse because it is not within the same scope. But I am stuck here.
This is the part that should contain the call to the function..
PHP Code:
myListener.onLoaded = function(oEvent:Object):Void {
trace("LevelObj.XObj > "+oEvent.success);
if (oEvent.success) {
trace(testVar); //CALL FUNCTION HERE IN SCOPE OF LevelObj
} else {
View 1 Replies
Dec 12, 2011
I've got a custom mxml component that currently implements IResponder. Passing this IResponder to a function works fine using this. This, however, includes implementing the public methods result and fault, so I'm asking if it isn't possible to pass a new IResponder to a function, somehow like this: object.function(someProperty:String, new IResponder());
View 1 Replies
Oct 19, 2006
Can I make function calls from within the onMotionFinished scope? See example belowe. Also tried by using the Delegate class...
var a_handler:Object = new Tween(params);
a_handler.onMotionFinished = function(){
test();
}
var test:Function = function():Void {
trace("hello");
}
View 1 Replies
Feb 9, 2010
public function addNewMc():void{
var newMC:MovieClip= new MovieClip();
this.addChild(newMC);
}
public function removeOldMc(newMC):void{
this.removeChild(newMC);
}
How can I create a new MovieClip within a method, which can be used throughout the class, without defining it at the top of the class? And for extra points, without using return. I can get it to work, if the first function addNewMc returns the value newMC, and passing that to any other methods.
View 1 Replies
Jul 15, 2009
i am quite newbie towards to actionscript 2.0 cos i am now learning on actionscript 2.0
here is the file attachment for you to check.Greetings.zipOutput cannot be worked.I am hoping to see the exact output:Greeting = Hello!Salutation = undefinedSubject: Brick Oven
View 2 Replies
Apr 27, 2010
I'm having some big issues with the scoping problems in my XMLConnect Class. I already found some things about the Delegate class online for setting the scope correctly, but my code still doesn't work the way it should Problem I need the XML data to be accesible in the public function Strip() because the user needs to put in some characters to strip from the strings in the xml file. Does someone known how to fix this scoping problems?
[Code]...
View 0 Replies
Oct 25, 2008
I'm not an experienced Actionscript user so I'm not sure what the normal way to associate a custom class with a movieclip that has been designed in the Flash IDE is. I made a class called Window to control a movieclip called TestWindow. There are some buttons in the movieclip whose
functionality I would like to assign the instance of class Window. How is this supposed to be done? Here's a representation of what I mean. I hope it is sort of clear. My actual problem is that the local variables are outside the scope of the onPress function but I also think there must be some other way of associating classes with movieclips that have been designed in the IDE.
View 3 Replies
Jul 6, 2011
My question deals directly with ActionScript 3, although it could possibly appear in other languages. Consider the global trace function found in AS3. Calling the method requires no imports and is globally available from all classes.
class A {
public function A() {
trace("Hello, A!"); // Hello, A!
}}
Now, what if I create my own class method of the same name? In AS3, if I have a class method trace and then make a call to trace elsewhere in my class, the call is made to the class method over the global function. Essentially, I've blocked my ability to call the global trace method.
class B {
public function B() {
trace("Hello, B!"); // no output
} public function trace(s:String):void {
// do something else.
}}
Now, I know the obvious answer is to say, "don't create a class method called trace." But what if I'm unaware of the existence of the global trace function? Or what if I have a desire to "override" or "block" the global function? Is doing so bad programming? Or is this just another example of how AS3 is a poor object oriented language?
View 3 Replies
Aug 5, 2004
Why I am losing scope on an array that i define as a private member in a class? I am able to access it from a couple of different functions but in one place inparticular it keeps coming up "undefined". What causes scope to be lost in a function for an array that is defined as a private class member?
View 4 Replies
May 8, 2011
Calling jQuery Function from Flash
if we have a jQuery plugin of the following style[code]...
Could anyone point me in the right direction for how this call can be made directly or clarify if it's just not a supported operation?
View 3 Replies
Apr 20, 2011
I have a custom class created by a main document class, and I want the custom class to run a function in document class after some time.
How can I sent the instruction from custom class back to the document class?[code]...
View 6 Replies