Flash :: Expose A Method In An Interface Without Making It Public To All Classes?
Nov 7, 2009
I have a issue where I'm working with a particular interface for quite a lot of things. However, I have a particular method that I want to be available only to a particular group of classes (basically, an internal method). [code]...
I am creating a library in AS3. Inside the library I make use of a bunch of classes/packages that need not be exposed to the end user of my lib. I want to only expose one of these classes.
I guess my questions are:
1) How are libraries commonly distributed in AS3?
2) Is there a .jar equivalent in AS3 that developers can include, but will only have access/knowledge of the classes I've declared as public?
i've got two classes and i'm not extending to MovieClip. I like to attach the mc in the constructor just because i'll be working with different MC's that have the same purpose.
however, im using private var loadedMC:Movieclip and now i've got another class that needs to be able to access the instance's variable.
for example, myClass.loadedMC , but this would mean having to make it public and I rather not go that route.
I'm tryng to make a public static method call another method, but Flash throws error 1180, sayng that the method called by the static method is undefined.
In Flash CS5 I'm getting 1195: Attempted access of inaccessible method testFunc through a reference with static type Doc. when compiling and can not understand the circumstances, which I have boiled down thoroughly.
MyDoc.as - My document class.
package { import flash.display.MovieClip; public class MyDoc extends MovieClip {
[code]....
I can get an error-free compile if I take the seemingly unrelated TLF text box out of the equation, either by changing it to a classic text box, deleting it, or unlinking its containing MC from MyClass. I can also get rid of the error by removing myOtherFunc()'s definition or moving it below myFunc()'s, which I had to do a few times just to convince myself that it was true.
Update: I just confirmed the same behavior on a friend's version of CS5. He's using a Mac as opposed to my Windows setup, and he only has the CS5 version installed, whereas I have both CS5 and CS4.
Is it possible to add my own custom property to the flash.display.Bitmap using a public static method? I'm trying to write a bitmap utility that does something to a bitmap, and stores a Number property onto it afterwards.
[Code]....
I'm still learning AS3.0 OOP, I think that this can't be done with this method. I think I have to make a new Class that extends 'Bitmap', add the prop there, and then in the Main.as make a new instance of that class, point to the target Bitmap, and run the method in the extended 'Bitmap' class (?).
I'm trying to define interface in which one method (initPage) needs to have different arguments in every implementation. How can I do this? Using ...args for me is not good, because I'm loosing strong type checking.[code]
I've got two classes running...one is a document class (EgoGame.as) and another is a class linked to several similar movie clips (Ball.as).I'm trying to access a public variable from Ball.as which has been declared in the doucment class EgoGame.as.When I run the test the outputs states the following...1120: Access of undefined property _ballPlaced.Here's my code. What I'm trying to do is remove the event listeners from the Ball.as when the _ballPlaced variable is true, so that the user can't drag and drop the balls after they've been placed in a zone.
I'm running into difficulty passing a strongly typed object, AttractView, to another method, addView() which expects an IWizardView interface that AttractView does implement. When I pass it as-is (as shown below), I get the compile error CaptureApplication.as, Line 120 1067: Implicit coercion of a value of type AttractView to an unrelated type IWizardView. Casting to either IWizardView or BaseView before passing yields a similar error at run time.
I work with Flash CS4 and lately I've been looking for certain classes to ease my work. To be more precise Atom/RSS2.0 parsing classes. But the best result I found needed me to work with FLEX. Now I can't get this to work with flash CS4. There's no apparent way to make this work. I can build my own parser or look for one that doesn't need Flex. But it looks like the future is more FLEX oriented.
EDIT : I know how Flex Code and SWC files should work. But every time I try to use them I get some bizarre error about missing classes and methods that are part of FLEX but not included in Flash...
I have a MainClass on a FLA file that defines both public, private, statics or not, properties and methods.I also have a package named 'components' that stocks Sprite sub-classes for my movie exportable clips. In one of them, I use the "this.root" property to access my main class instance elements at runtime.When I access public method references, same thing, I can trace them and have a true reponse to the question : [myPublicMethod is Function] ? BUT, when I want to execute the public methods, like MainClass (this.root). myPublicMethod(), the compiler boldly throws this at me :Error 1195: Attempted access of inaccessible method myPublicMethod through a reference with static type MainClass.
I have a question about classes. I just learn that static means that functions and/or properties are specifics to a class, but is it a synonym of private? And why statics (not available to any instances?) properties and/or methods can have a public (available anywhere else (timeline)) access modifier? PS: I just start with classes.
package { import flash.display.Sprite; public class MySprite extends Sprite{
[Code]....
and extend that class, if more than one internal classes are defined:
package { public class MainClass extends MySprite { public function MainClass():void{}
[Code]....
ReferenceError: Error #1065: Variable MainClass is not defined.Note that this only happens (as far as I can tell) when the public class of the package extends another class, and multiple internal classes are defined. The internal classes don't even need to be instanced or referenced to generate the error (the bare-bones code above will error out). If only a single internal class is defined, it works fine (no error). Even if the internal class is instanced.
How to access a public method in the swf loaded in a new ApplicationDomain?
ActionScript Code: var appDomainA:ApplicationDomain = new ApplicationDomain(); * var contextA:LoaderContext = new LoaderContext(false, appDomainA); var loaderA:Loader = new Loader(); loaderA.load(new URLRequest("application2.swf"), contextA)
I want to access a public method in application2.swf from the main swf that loaded it.
I have two classes that I am trying to get to intereact, main.as which is the class attached to the stage and then light_mc.as which is attached to a movieclip.
I have a function in main that I would like to access in light_mc. I have set it up so main stores "this" in a variable called instance so I can easily access the functions within main.
I have to know if a public method has been called from outside the class or from inside. The reason is that depending on this, one of the actions to be executed in this method vary a bit.
I have this sample class Code: class TestPrivate{ public function TestPrivate(){}; private function getGo(){ trace("can execute"); }}
And then after instantiate I just calling the method...for testing the "public" and "private" keyword purposing only...
Code: import TestPrivate; var obj1 = new TestPrivate(); obj1.getGo();
The result is still can be execute even though I put the private keyword in front of the methods. So what's the private keyword stands for actually...I thought it prevent been get accessed from outside...
I have a class member in an ActionScript 3 class that looks something like this:
private var m_myvect :Vector.<MyType> = new <MyType>[];
I'm exposing it through a getter, like this:
public function get mydata() :Vector.<MyType>
Which doesn't help when I use it like this:
for (var o:Object in inst.mydata) { ... }
... because the type of o is not MyType, but Number instead, because it enumerates the vector indices instead of the data.How would I expose only the data within the vector in a way which:Does not expose the data in a way which allows it to be modified?
I have two SWFs: main.swf and external.swf. main.swf needs to access some methods in external.swf, so it loads external.swf into itself and uses getDefinitionByName("package.Class") to access the class and one of its methods:
var ExternalClass = getDefinitionByName("package.Class") as Class; var ClassInstance = new ExternalClass(); var NeededFunction:Function = ClassInstance["NeededFunction"] as Function; var response:String = NeededFunction(param);
Now, I need to extend the functionality of NeededFunction (which is a public method)... I know it's possible to override public methods, but how would I go about this with a dynamically loaded class?
I was thinking I could do something like this, but it doesn't work:
var ClassInstance["NeededFunction"] = function(param1:uint):String { var newString = "Your number is: "+param1.toString(); //New functionality return newString; }
I need to be able to call a method from a component located under the main application in Flex 4. Can anyone tell me please how to do this without using FlexGlobals please?[code]
I have the below script as part of a small application I'm building. The script just creates cue-points along a movies timeline so we can add events etc to those cue-points.
[Code]....
It's creating the cue-points well, although I'd like to use the below variable outside of this function.
Code: var stampName When I try and use it I get an access of undefined property error, which I believe relates to the variables being private and within the function - but I can't seem to find a method to get this varibale public.
There are many tutes on the web on how to make interface elements, such as drop down menus, or accordion menus. The example Menu Class includes all the event listeners and functions. It invariably ends with the CLICK event function tracing some comment so you know it works. But no information on how to implement the Menu Class. So say you have a Main Document Class that instantiates a Menu Class. How can you pass the CLICK event back to the Main Document Class to do something with it? As far as I can see, the Menu Class can build the menu but all the listeners and functions for it have to reside in the Main Document Class. Or do you have to build a custom Class that extends the Event Class?
I'm trying to use Greensock LoaderMax on a Starling Framework project, but since Starling have a lots of its own class, how I can make it work with other classes that is using the native class?
I think I understand how to make a interface but the problem is im unsure as to how to add it to my existing code! To make a interface (as far as i know) You can create classes such as mainScreen, intructions and so on. Ok i get that, make the classes then add ther buttons from the library i these classes. But i followed a tutorial bu Emmanuel Feronto, and adapted that to the needs of my game.
So im unsure as how to add these 'Screens' to my current class, the I currently only have 1 class, Main which currently has 300 lines of code, and i dont know how to break it up into smaller classes. Thats the problem i think, The main is quite large, normally i have heard people keep this clear... But then say i made a bland main, and added the screens into that then how do i make the main that makes the game play on the play button?