ActionScript 3.0 :: Call Some Methods In Class A From B?
Dec 18, 2009If i instantiate class B (not a display class) in class A whats the best way to call some methods in class A from class B ?
View 3 RepliesIf i instantiate class B (not a display class) in class A whats the best way to call some methods in class A from class B ?
View 3 RepliesI'm trying to call methods from a class to no avail. It just tells me that I have undefined methods.[code]
View 3 Repliesi have a main movie. i use a loader to load a "example.swf" file. then i place that file inside a holder movieclip. in example.swf, i have an instance of a class i just wrote. this class has some particular methods. from my main movie, i want to call the methods of the instance of my class i have in example.swf. how can i do that??? i know it's a kind of casting, but none seems to work.
View 1 RepliesI've written a pre-loader for my game, it uses Loader, URIRequest and LoaderInfo to display a bytes left/total counter as the main game SWF loads - this all works fine.
However what then happens is that the main SWF constructor is called, so the game starts running "in the background" while the pre-loader finishes off.
I moved the 'start game' code from the constructor into a different function but I'm now left with the issue of how can I actually tell the main game SWF to start?
You can't do loader.content.go() (where go() is the function I want to call).
How can I access methods of a loaded SWF? Or is there another way? I tried dispatching a custom Event from the pre-loader, but the game SWF just never heard it - but is this the right way to go about things?
I really want to pass some bits of data from the pre-loader into the main game SWF too, but until I can figure out how to make them both talk I'm totally stuck! Is there a way the game SWF could reference any variables set by the preloader?
I'm interesting in following methods:
Code:
Function.apply ();
Function.call ();
I tried to copy Function.call () example in my custom class, but errors occurs.
I hav created a pure actionscript project which defines few methods.What i want to do is to expose an interface for the .swf file generated through this actionscript project created in flex to call swf's methods.This is the following code that i tried writing in mxml:
<mx:Application>
<mx:Script>
import mx.managers.SystemManager;[code]....
what error i get is cannot convert AVM1Movie to mx.managers.SystemManager.How can this be rectified?
i never really worked with .as files a lot, and i can't seem to get it right, not can i find a good tutorial. Well, in this case here's my problem:I got my main file which imports MakeButton.as. It then instantiates a class of MakeButton in order to call it's method makeButton. But how can i just call the Methods in MakeButton.as without having to instantiate anything?
[Code]...
How to call java/c++ methods from flash cs3/flash 8.0 ? i required both flash and c++/java codes... tell me wher to keep those places.... to run and see the desired output..
View 2 RepliesHow to call a javascript method from flash ?? am having a simple javascript code ie
<script type="text/javascript">
function helloWorld() {
alert('Hello World');
}
</script>
Now how to call the method helloWorld() from flash ??
Similarly how to call a php method also ?? am having the php code as,
<html>
<body>
<?php
[Code].....
now i want to call writeName() from flash ?? how to achieve these things from flash ?
Wats the code i have to write in flash cs3 ?
i've been struggling with this issue. I need to load a flex swf into a flash as3 shell and then call its methods. I can see the flex swf no problem - but calling its methods - nothing works. Now considering LocalConnection or even ExternalInterface to communicate between the two.
View 2 RepliesI have a parent class that instantiates a MenuClass and handles transitions between pages.[code]And here's the MenuClass which creates forward and backward buttons. Clicking each will tell the above ParentClass to transitionForward() or transitionBackward() respectively.[code]One one hand, I feel like the MenuClass is too tightly bound to its parent and is thus less reusable. On the other hand I feel like, in the interest of keeping everything self contained, it's not the ParentClass's responsibility to reach into the MenuClass instance and add event listeners there. This seems like there should be some kind of OOP rule-of-thumb to govern this kind of relationship.Is my MenuClass too tightly bound to its parent? And if so, do you have any suggestions that would loosen that coupling?
View 4 RepliesI am talking about doing something like this: [URL]
from flash by using ExternalInterface probably
I m new for OOP concept see this is my class, How this class will return values???
[Code]...
I'm new to AS3. I've got two classes.
damnMoles.as and startBtn.as
The damnMoles class uses a method called randomPlay();
ActionScript Code:
public function randomPlay():void {
this.gotoAndPlay("moleLabel"+randomNumber(1, 18));
}
Which basically allows the looped mole animation to start from various points in its timeline. I could probably use a different method to do this using an interval variable, but I originally coded this in AS2.0 and I want to update it, to see how this are different.
damnMoles class is attached to 6 mrMole# instances on the timeline.
Originally I used code on the main stage timeline to start the animation of the moles.
ActionScript Code:
startBtn.addEventListener(MouseEvent.CLICK, startClick);
function startClick(event:MouseEvent):void {
mrMole1.randomPlay();
}
This works fine, however, I would like to refrain from timeline code and use .as files. My startBtn class looks like this, but I get the error:
1120: Access of undefined property mrMole1.
ActionScript Code:
package com{
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.display.Stage;
[Code] .....
So, how does this work? When I want to use a method from another class that has multiple instances on the stage?
I need to call a method writeln() from the method buttonClick() which is in another class. Also need from a method of readResponse () method call loadSocket (str: String)
Errors:
Attempted access of inaccessible method writeln through a reference with static type main2.as$36:CustomSocket.
Call to a possibly undefined method loadSocket through a reference with static type Class.
Here is my code with 2 classes:
ActionScript Code:
package {
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
[Code] .....
What if you have methods you want to use in your project, that really have no need of a class, or in other words, there is no need for an "object" associated with it. It's not going to have member variables, so why bother making it a class?
for example,
I want to create a randomNumber method, takes two numbers, low high, returns a random between or equal.
Originally in my code I had a very top level class i just called globalLibrary that extended movie clip, i put my randonNumber method there. Then every class in the project extended that. I got the method scoped properly, but to me it looks like a hack.
For example, the most basic functionality in flash like +, even = , trace, etc. Are these also methods defined in some class that we are extending? Or are they methods that have no object associated since that would seem to make just as much sense.
why can't I just create a file of methods, and import that file and have access to these methods?
SETUP: I have a MX2004 project where I'm attempting to pass a movie clip to a class, and have a method of the class act as the function for the onEnterFrame. PROBLEM: The class appears to lose reference to the movie clip when onEnterFrame() is called. TO DUPLICATE: Two files are needed, they are outlined below:
[Code]...
I need a way to reference to object (or the class methods inside). I have a button "Add box" and when it is pressed it creates a new instance of class "MyBox". The thing is everyone of these objects get the same name "box".Here's a hint of what it's like:
Code:
var arrBoxes:Array = new Array();
// var n:Number = 1;[code]...
Inside of the addBox function I can easily refer to the Object with just "box" (for example box.name = ..)but when in another function I cannot (and by then I might have created many "box"es).
Is there any way to add methods to the existing MovieClip class so that later I can use them everytime I instantiate a MovieClip? Something like this:
PHP Code:
package { import flash.display.MovieClip; public class myClass extends MovieClip { public function myMethod() { //do stuff } }}
Then, without instantiating myClass, I want to be able to call that method like this:
PHP Code:
var newMc:MovieClip = new MovieClip();newMc.myMethod();
Here is the situation:I have created a movieClip named "tp_crack" on the timeline and created its class using linkage called "tp_crack".The tp_crack mc is like a small rectangle which breaks in 3 seconds when it is played.I have a seperate class in which I have used tp_crack to create many instances of tp_crack going by the names: cracked1","cracked2" etc.These instances are present in another movieClip (this time created within the class) called "crackContainer".Now I have added the following code to check for hitTest of those cracked1,2,3...... with a spaceship.The hitTest works but flash does not recognize the pieces as movieClips and does not play them as required, instead it gives me an error saying:1061: Call to a possibly undefined method play through a reference with static type flash.displayisplayObject.
for (var i:uint=0; i<crackedPieces; i++) {
if (crackContainer.getChildAt(i).hitTestPoint(Spacesh ip.x,Spaceship.y+(Spaceship.height/2),true)) {
[code].....
I have this base class
package sevengames.miranda.front.res {
import flash.display.MovieClip;
import flash.text.TextField;
[Code].....
I then, in the Flash document, create a movie clip which has this class set as the "Base class" in the properties. However, if I then do this.updateText(); in the movie clip's frame script, it complains
TypeError: Error #1006: updateText is not a function.
at miranda_fla::MenuButton_3/frame1()
Why doesn't it work? I know the class is read and compiled, because I had an error there which was reported.
Any good 'real world' examples of when and why you might use the map and filter methods of the new Vector class in Actionscript?
View 1 RepliesI am writing class that extends adobe air PNGEncoder,
I want to use the writeChunk method, but it seems to be private static and i cant seems to use it with my code But it gives the error as below
[Code].....
I want to add a custom method so that any MC can use it like this - Code:text1.fadeIn(2) - which would fade text1 in over 2 seconds. The actual method isn't important, it's the way to add it as a custom method for ALL MCs that is confusing me.I can add it inside the document class (that extends MovieClip) like{/*fade in over tt seconds etc*/};But pretty much everywhere I look peoples are choking on their coffee shouting not to use that method. So is there a nice, clean way to do it without using prototype?BTW I want to add these methods in a class that is imported into the main document class at compile-time. So my main doc class has code specific to this SWF but the general external classes like Effects and Transitions are imported as needed.
View 6 RepliesWhen I create classes, often I want to remove methods of the parent class (such as addChild(), perhaps), and I just override the method and have it throw an error. Is there a way to remove it completely?
View 9 RepliesI have a class1 in which I create a child from a class 2. Of course I can access class2 properties, fields and methods from class1. But is there a way to access class1 fields and methods from class2? Like to go a step back in the hierarchy?
View 1 RepliesI've got a custom class (using AS2) that mostly does things like set the score and level of a game, as well as sets the player's lives on the screen. I need to unload and attach MovieClips within the Lives control function, which require those methods from the MovieClip class. I don't think I need to extend this class from the MovieClip class, I think I need to import the class somehow. I don't know the path though..something like mx.MovieClip.
View 3 RepliesIn AS2 we can not add methods n properties to built-in classes in the way we do in AS1. Like we would -say- write the custom "isNatural" method on the "Math" class as follows : * The following code is valid in AS1 but not in AS2
[Code]...
As the "Math class" is static internally. We know why we can not add custom methods n properties to every class, as the way we do in AS1. Later I came up with senocular' s very nice tutorial on OOP in AS2. And now i know how we can do it in AS2 style in an efficient n organised way. But i have a problem with the following code. It should not work ! but it does... * Following code is valid for both in AS1 and AS2.
[Code]...
does anyone knows the "time complexity" of Dictionary class methods ? for example, is the ""get"" is an o(1) time complexity ?
[Code]...
and another question in the same topic, how does the Dictionary "generate" an 'equal function' & 'hashcode' (assuming same implementation as in java's HashMap) from the object passed as a key? is it efficient ?
I have an urgent task to implement in my project code. I can't able to access the new properties and methods which are present in FileReference Class. For load() ,save() methods needs runtime version of Flash Player 10. I need to include the flash player 10 in CS3 publish settings Version. Otherwise you can suggest how i can able to access the FileReference class new properties and methods without CS4.
View 7 Replies