ActionScript 3.0 :: Detecting Event In Private Function In External Class
Mar 28, 2011
I'm building a drag and drop quiz. each draggable mc (drag#) has a base class of DragDrop. I want to detect when an drag mc has been dropped on a target
Code:
if(this.hitTestObject(target)) {}
And then add a new drag from the drops Array. so that each time a drag finds its target a new one appears. I tried to make a public var named dropped to switch from "yes" to "no" in the drop function. and even tried making the drop function public.
This code is on the timeline
stop();
var drag1:Drag1;
drag1 = new Drag1;
addChild(drag1);
drag1.x = 100;
drag1.y = 100;
[Code] .....
is there a difference between classifying a function 'private' or 'private static' in a singleton? It seems that they both do the same thing. Maybe some difference in performance?
These two functions are taken out of my as class file, even though the setInterval is never cleared it only calls generateParticles 1 time. Someone please help me figure this out. I have been messing around with it over an hour but still can find why its only called once. emit is a private var Number declared outside the function in the class.
How do I call a private function from an external ActionScript3 document? I'm working in Flash Builder 4, and I need to call a private function from an external AS3 document. I think I've imported it correctly....
there are classes definitions where all their methods are private my question is why are they private, because i've tried a code wherein i changed all the private access modifier to public and nothing changed!
what if you make an instance of that class with all its method private, how are you be able to access that on another class. coz i know private methods are only accessible to the class where they are declared! will the instance of that class be able to access the superclass's private methods!
on private variables, it's still not clear to me as to why make a private variable and then use a getter and setter, when you can simply make it public! are these variables called static?cause on the way i understand it private functions and private variables are static?
I have written a framework that facilitates RPC calls between AS3 and PHP 5 called FlashMOG. I recently got a forum request that has introduced a pretty bizarre question regarding access control. This will be a lot easier to discuss if you have access to the FlashMOG 0.3.1 client source which is here:
[code]...
The basic idea is that I have a FlashMOGService class which has an RPCSocket member that it may share with other FlashMOGService objects. The idea is that you can create two distinct FlashMOGService objects and have them both connect to the same host/port via socket. I use my special RPCSocket class for two reasons:
1) Let developers use one port but separate functionality into two distinct services...a form of multiplexing i guess
2) RPCSocket adds functionality to the standard Socket class that works to serialize and unserialize data and get it where it needs to go. The essence of the problem here is that created a class with a FlashMOGService object as a member and has tried to assign a private method of his class as an event handler to the FlashMOGService object:
[Code]....
My initial thought is that this should be fine because it's all done within the class. However, when I consider the monkey chain that results in this function being called, it seems almost logical that it wouldn't work. The problem is that the browser freezes when a socket message arrives that tries to call the service's client method, _service.client.firstClientMethod. This client firstClientMethod is attempted when data arrives from the server on the Socket (an RPCSocket, actually). The RPCSocket class deserializes the socket data and extracts an array with a service name, a method name, and an array of arguments. It looks into its own private class variable (an array of services using the RPCSocket) and tries to invoke whatever function was assigned thusly:
[Code]....
I'm guessing there's some kind of infinite loop going on to check access control for the various intertwined classes.
Okay so you've got your private vars in your AS2 Class, you think they're all safe right? Wrong.
Doing a trace(MyClass.myvar); will spit out an error that the var is private and you can't touch it.
But a trace(MyClass["myvar"]); will work perfectly fine. You can use it normal, without any setters getters outside the class.
Is there a way to protect against this? I think this is a huge security flaw. I know it's simple OOP, but a private var in an object should have rules.
I am working on a small section of my game and am attempting to detect key presses from an external class but I cannot get it to work. This code worked just fine when within the document class but now it's unresponsive. I'm not getting any errors, simply no activity whatsoever.Here's the applicable code:
My document class:
Code: package { import flash.display.MovieClip; public class Engine extends MovieClip
i'm trying to modify some code and can't figure out what the issue i'm having it. this is the(shortened) code:
public static function Lose():void { trace("OVER!"); Clock.stop();[code]...
this is the error i get: 1180: Call to a possibly undefined method OverIt.i just want to call a function from inside of the public static funtion.both function are inside this class:
I have a document class called Main.as In the class constructor I have the following listener:
enter code here var listeningFORModeChangeToStudent:Sprite = new Sprite; listeningFORModeChangeToStudent.addEventListener(TellAllModeChangeToStudent.STUDENT,exp); addChild(listeningFORModeChangeToStudent);
[code]....
In a third class I make a call to the despatcher in the previous class:
enter code here var ThisTellAllModeChangeToStudent:TellAllModeChangeToStudent = new TellAllModeChangeToStudent; ThisTellAllModeChangeToStudent.tellAllModeChangeToStudent();
I have trace statements in eveything and from this I know the despatcher in TellAllModeChangeToStudent is being called.The problem is that the listener in the main.as is not calling the function exp.I cant see why and I dont know how to check if the listener is actually seeing the dispatch event?
I am trying to access a function in a loaded swf that has external class.. I would like to avoid having to put the function on my "Main" Doc class in the external swf and instead access the function directly from the class
This is what ive tried so far and it's a no dice:
private function startLoad(){ var loader:Loader = new Loader(); var req:URLRequest = new URLRequest("one.swf");
i have created a Vehicle.as file and a Car.as file which are in the same project. The problem i am having is trying to use the properties in my Car.as from my Vehicle.as file.Vehicle.as
In my main class (package) I have a function (tipTrendHandler) which creates an object TextBox. The instance in the example is ttrend. The class is imported. However when trying to access the object and apply e.g. a method, declared in another function (e.g. displaySequence) it seems this object is unknown.
ActionScript Code: package com { import flash.display.* import com.mycompany.TextBox;
I try to serialize objects with their private attributes, in Flex.
The introspection API does not seem to allow it:
"The describeType() method returns only public members. The method does not return private members of the caller's superclass or any other class where the caller is not an instance."
Is there another way for an instance to know the name of its private members?
I have a class which deals with a lot of visuals, which essentially are movieclips. So I have around 50 privately declared movieclips in the class. Would it be a good idea to put them in a dictionary and retrieve them by their name (as key) , put them in an array or just leave them as they are?
My issue is the visual look of my class right now with that many private members, looks like a mess visually.
I have some code from a CS3 app composed of the .FLA file with an .AS file for the class that had definitions for two private classes in it. Yesterday I brought the files into CS4 and noticed that they did not compile. Gives an 1120, access of undefined property and names a constant. I have reduced this problem down to bare bones and it still occurs, so it is a bug in CS4.
I have a class that creates an array from a config xml file. I set a private variable in that class and use a getter in other classes to access the array. The routine that uses the array does the following: - Call the getter and assign the returned value to a local (private) variable tmpArray. the getter is a simple return() using a value that is established in the constructor. - Uses a for loop to itterate over the contents - Uses array.shift() to pop the item in tmpArray
The next time I run the routine, the contents of the array is empty. I'm using the same getter. I implemented the getter when I tried to manage both arrays in the same class figuring that as long as the original array was private (i also tried static), that the value would not change. I have since worked around the problem by moving the routine that fills up the original value from the constructor to the getter. So, consider the following code:
import flash.events.Event; btn.addEventListener("click", btnHandler); var myArray = new Array(); var myTmpArray = new Array() myArray = ["one", "two", "three"]; myTmpArray = myArray; function btnHandler(evt:Event) { [Code] .....
If I create a variable myVar and set it to 1 then set myOtherVar = myVar, the both equal the same value. If I change the value of myOtherVar, myVar is not affected. But using the shift() method changes both the original and the copied array.
Currently I have two classes which are "bullet" and "enemy".There are two instances of the enemy class.Code from an ENTER_FRAME event in the Bullet Class:
The Enemy Class has a private variable called "hits".What do I have to do in order to reduce the hits of the instance of the enemy that was hit by the bullet?
I have a Color class where all the data is stored in a single uint named "_value". However, the constructor for Color looks like this: public function Color(r:uint = 0, g:uint = 0, b:uint = 0):void { _value = (makeChar(r) << 16 | makeChar(g) << 8 | makeChar(b)); }
If I want to create a clone() method, I have to first convert the "_value" variable to an RGB object, then, the constructor automatically converts the object back into a hexadecimal value. Blatent waste of efficiency! However, I would rather have the constructor be user friendly and allow them to type in each color value instead of one hex value (they can use the Color.fromHex() if they really want to, but it does the same as the clone() method and converts back and forth).
Is there any way to instantiate a class without going through the one single constructor function? Any way to set up a private constructor in addition to the public one? Most Visual Studio languages allowed you to have multiple constructors, and the chosen constructor is determined by the passed in arguments. This was really convenient, but sadly, AS3 only allows one constructor, right?
I am stepping back up to AS3 after realizing that it would be easier if I learned AS2 prior to trying to understand AS3 (all documentation, online and in books, reference AS2..."in AS2 this was done this way.I am writing my first external class and trying to associate it with an object created in the Flash via the Library Linkage.I have a movieClip on the stage and have it associated with the following class that doesn't show any transition when tested.[code]
i am trying to activate a function within a class on a mouse rollover -this is AS2 in CS3 and i have the following in my Class.as:
[Code]....
the global.pane_array is specified in my FLA Obviously i would like to see the trace from the array, but nada.... if i put the movePanes() outside the rollover event, it works fine... however this does not achieve my goals
also if i declare the function as a global function from within my FLA, and then call it on the rollover e.g. _global.movePanes() - it works!
I have a question about accessing properties of a custom class from within another class. I can do it, but I'm not sure if I am doing it the right way or if there is a simpler alternative. I have a class called legion it contains a couple of properties, a sprite called legio and an integer called loc I import the legion class into another class called Main.
Within Main I have a loop to create many versions of legion, passing parameters so that they all have unique loc values. These are put into an array called legarray:
I'm setting up functions in a document class file, then from there I am going to call that function from a movieclip in flash. For some reason, maybe I have things set up wrong, but it is throwing me errors such as below: Line 37 1013: The private attribute may be used only on class property definitions. What am I doing wrong here and is there something I am not understanding? Here is my .as code. modal.as > package