Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Problem Accessing Main Timeline Textfield From Class



Hello,I'm having a real hard time trying to work this one out. I'm pretty new to AS3 and OOP in general, but I'm slowly progressing.I have an uploading class that I have made that uploads mp3s to a server, that works fine, the problem I'm having is inputting information about the file into a textfield that is located on the main stage. I can't work out how to refer to it properly, as the old AS2 method of dot syntax doesn't work.I had the uploader working fine when it was is in it's own fla and not utilising external classes, and the textfield displayed exactly as I wanted. I just want to get my head round using classes and thus having cleaner, modular code.I've searched all day and found some stuff that I think might help, such as displayobject and defining root and stage, but I can't really get my head round how to do it.Here are some code snippets that hopefully you'll be able to make sense of...The main fla code:
Code:
mUpload.bPlay.addEventListener(MouseEvent.CLICK, uploadFile);function uploadFile(evt:MouseEvent):void { var tester:Uploader = new Uploader(); }
and the Uploader.as file code:
Code:
package { import flash.net.*; import flash.events.*; import flash.display.Sprite; import flash.text.TextField; public class Uploader extends Sprite{ private var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3"); private var allTypes:Array = new Array(fileTypes); private var fileRef:FileReference = new FileReference(); public var tStatus:TextField; public function Uploader():void { fileRef.addEventListener(Event.SELECT, selectHandler); fileRef.addEventListener(Event.COMPLETE, completeHandler); try { var success:Boolean = fileRef.browse(allTypes); trace("Uploading..."); } catch (error:Error) { trace("Unable to browse for files."); } } private function selectHandler(event:Event):void { var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3"); var allTypes:Array = new Array(fileTypes); var request:URLRequest = new URLRequest("http://www.blahblah.com/alive/uploads/uploader.php"); try { fileRef.upload(request); } catch (error:Error) { trace("Unable to upload file."); } } private function completeHandler(event:Event):void {tStatus.text = "Successfully Uploaded - " + event.target.name + " - " + event.target.size; } }}
I have a textfield that i have created on the stage called tStatus within which I want to display some information once I have uploaded the file. Any help would be greatly appreciated, for my sanity's sake



KirupaForum > Flash > ActionScript 3.0
Posted on: 04-24-2008, 03:56 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Problem Accessing Main Timeline Textfield From Class
Hello,

I'm having a real hard time trying to work this one out. I'm pretty new to AS3 and OOP in general, but I'm slowly progressing.

I have an uploading class that I have made that uploads mp3s to a server, that works fine, the problem I'm having is inputting information about the file into a textfield that is located on the main stage. I can't work out how to refer to it properly, as the old AS2 method of dot syntax doesn't work.

I had the uploader working fine when it was is in it's own fla and not utilising external classes, and the textfield displayed exactly as I wanted. I just want to get my head round using classes and thus having cleaner, modular code.

I've searched all day and found some stuff that I think might help, such as displayobject and defining root and stage, but I can't really get my head round how to do it.

Here are some code snippets that hopefully you'll be able to make sense of...

The main fla code:



Code:

mUpload.bPlay.addEventListener(MouseEvent.CLICK, uploadFile);

function uploadFile(evt:MouseEvent):void {
    var tester:Uploader = new Uploader();
    }

and the Uploader.as file code:


Code:

package {

    import flash.net.*;
    import flash.events.*;
    import flash.display.Sprite;
    import flash.text.TextField;
   
    public class Uploader extends Sprite{

        private var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
        private var allTypes:Array = new Array(fileTypes);
        private var fileRef:FileReference = new FileReference();
        public var tStatus:TextField;
       
        public function Uploader():void {
            fileRef.addEventListener(Event.SELECT, selectHandler);
            fileRef.addEventListener(Event.COMPLETE, completeHandler);
            try {
                var success:Boolean = fileRef.browse(allTypes);
                trace("Uploading...");
                    } catch (error:Error) {
                trace("Unable to browse for files.");
            }
        }
        private function selectHandler(event:Event):void {
            var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
            var allTypes:Array = new Array(fileTypes);
            var request:URLRequest = new URLRequest("http://www.blahblah.com/alive/uploads/uploader.php");
            try {
                fileRef.upload(request);
            } catch (error:Error) {
                trace("Unable to upload file.");

            }
        }
        private function completeHandler(event:Event):void {
tStatus.text = "Successfully Uploaded - " + event.target.name + " - " + event.target.size;
        }
    }
}

I have a textfield that i have created on the stage called tStatus within which I want to display some information once I have uploaded the file.

Any help would be greatly appreciated, for my sanity's sake

Problem Accessing Main Timeline Textfield From External Class
Hello,

I'm having a real hard time trying to work this one out. I'm pretty new to AS3 and OOP in general, but I'm slowly progressing.

I have an uploading class that I have made that uploads mp3s to a server, that works fine, the problem I'm having is inputting information about the file into a textfield that is located on the main stage. I can't work out how to refer to it properly, as the old AS2 method of dot syntax doesn't work.

I had the uploader working fine when it was is in it's own fla and not utilising external classes, and the textfield displayed exactly as I wanted. I just want to get my head round using classes and thus having cleaner, modular code.

I've searched all day and found some stuff that I think might help, such as displayobject and defining root and stage, but I can't really get my head round how to do it.

Here are some code snippets that hopefully you'll be able to make sense of...

The main fla code:


Code:
mUpload.bPlay.addEventListener(MouseEvent.CLICK, uploadFile);

function uploadFile(evt:MouseEvent):void {
var tester:Uploader = new Uploader();
}
and the Uploader.as file code:


Code:
package {

import flash.net.*;
import flash.events.*;
import flash.display.Sprite;
import flash.text.TextField;

public class Uploader extends Sprite{

private var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
private var allTypes:Array = new Array(fileTypes);
private var fileRef:FileReference = new FileReference();
public var tStatus:TextField;

public function Uploader():void {
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
try {
var success:Boolean = fileRef.browse(allTypes);
trace("Uploading...");
} catch (error:Error) {
trace("Unable to browse for files.");
}
}
private function selectHandler(event:Event):void {
var fileTypes:FileFilter = new FileFilter("mp3 (*.mp3)", "*.mp3");
var allTypes:Array = new Array(fileTypes);
var request:URLRequest = new URLRequest("http://www.blahblah.com/alive/uploads/uploader.php");
try {
fileRef.upload(request);
} catch (error:Error) {
trace("Unable to upload file.");

}
}
private function completeHandler(event:Event):void {
tStatus.text = "Successfully Uploaded - " + event.target.name + " - " + event.target.size;
}
}
}
I have a textfield that i have created on the stage called tStatus within which I want to display some information once I have uploaded the file.

Any help would be greatly appreciated, for my sanity's sake

Accessing Class Var From Main Timeline
Hi all! Well I've been working on this for a couple of days now and just can't seem to get it to work right...... I'm still getting my feet wet with as3 and like it more and more everytime I use it.... almost.

Anyways, here's where I'm running into trouble.

Here's a dumbed down version of my project with all the other usless drivel excluded. Basically what I'm trying to do is declare a var and give it a value in my class. Then I want to be able to display that value on the stage and use it in the main timeline. Seems simple enough....

I need to be able to pass the var from the class to the main timeline for use.... Any help on this would be GREATLY appreciated.

Thanks.








Attach Code

//Actionscript code on first frame of main timeline

//Imports my class... works fine.
import folder.testing.TestClass;

var testClass:TestClass = new TestClass();





//Class Code
package folder.testing {
public class TestClass {

public var someNumber:Number;

public function TestClass() {
trace("test class working");
someNumber = "1234";
trace(someNumber);
}
}
}

Accessing A Variable On The Main Timeline From A Class
Not a question - just info for people.

For some reason I reckon someone might benefit from knowing this. I struggled to learn some basics of communicating from Classes to the Timeline, and thought more information in Flashkit.com could be good.

MovieClip(root).variableNameOnTheTimeline

I kept trying 'this.parent.variableNameOnTheTimeline' but it doesn't work.

A way when using classes through Inheritence is to make a variable in the Class: eg 'var thisParent:*;' and then after the MovieClip or Object has been added to the stage, you can do 'thisParent = event.currentTarget.parent;'
and then you can access the mainTimeline.

Accessing The Main Timeline From A MC?
the navigation of my site is in a movie clip, from which I would like to access frame 4 on the main timeline of my movie. The code is gotoandplay(4), which write now jumps to the frame 4 of the movie clib instead of frame 4 of the swf.
Could you tell me how to access the main timline from a mc?

Accessing Main Timeline Problem
I'm trying to access a frame in the main timeline from a button within a movieclip. using flash 8.

here's the code

on (release) {
_root.gotoAndStop(6);
}
it stops at frame 5. any ideas?
thanks

[F8] Accessing Mc In A Button From Main Timeline
Hey guys, so i have two buttons on the main timeline, button1instance and button2instance. This code is attached to button2instance that is to trigger the behavior inside button1instance:

on (rollOver) {this._parent.button1instance.mc1instance.gotoAndP lay(2);}

where mc1instance is the instance of movieclip mc1 on button1's stage in the 'over' frame.

well, it's not working

this approach works when i access mc's in the same timeline. for example:

on (rollOver) {this._parent.somemovieclipinstanceonsametimeline. gotoAndPlay(2);}

so what am i doing wrong? is it that i'm trying to tell a movie clip in a button what to do? any suggestions on how to get this working?

Accessing Main Timeline From Loaded Swf
Hi all,

I'm running into a timeline/display list problem.

Inside my main movie ("main.fla") I am loading a swf ("sub.swf"). I'd like sub.swf to control the main.fla timeline. I've researched and tested a number of methods but haven't had any luck.

I'm currently using this line.


ActionScript Code:
MovieClip(root).gotoAndStop("btn_advertising");

Thank you,
Joe

Referencing Clips On Main Timeline From My Main Document Class
Hi All,

I'm trying to reference clips on the main timeline either in or via my main Document class, but if I declare any clips as public in the class body as I would have done is AS when linking an external class, I get:


Code:
1151: A conflict exists with definition tfLength in namespace internal.
If I don't declare the clip, then I can reference it from within the same class with this.tfLength, but other classes complain it the Document classes tfLength variable doesn't exist!

So how do I reference a clip on the timeline in my class?

Thanks,
Dave

(tricky) Accessing Buttons From The Main Timeline
I am trying to load images externally with the loadMovie function. The actionscript is on the main timeline and i use:

this.tabs_mc.zerofive.but1.onRelease = function() {
infoField._visible = true;
startLoading("pix/2005/2.jpg");

so far it has worked perfectly.

on the next bit i want to put the same code on a button (but14) in a movieclip (zerosix) on the 2nd frame of the tabs_mc.

I think it should be tabs_mc.zerosix.but14.onRelease....
but alas it does not work.

[F8] Accessing Method In An Mc In A Button From The Main Timeline
Hey guys, so i have this code attached to a button on the main timeline:

on (rollOver) {this._parent.th1p.th2.gotoAndPlay(2);}

where th1p is the instance of another button on the same timeline and th2 is the instance of an mc on th1p's stage in the 'over' frame.

well, it's not working

this approach works when i access mc's in the same timeline. for example:

on (rollOver) {this._parent.thx.gotoAndPlay(2);}

where thx is the intance of an mc.

so what am i doing wrong? any suggestions?

Help: Accessing Main Timeline Var From SWF Loaded In A UILoader
Greetings enlightened ones

Here's my problem:
I have a main swf movie in which a var is defined on its main timeline. I have a UILoader on that main timeline which loads an other SWF.

Here' what I need to do: How can I let the loaded SWF in the UILoader access that variable on the main timeline of the main swf?

Please help

Accessing Buttons In External Swf From Main Timeline
Hello,

I am loading external swfs into a main swf. So I have main.swf which loads menu.swf, along with ssp_home.swf and home.swf.

These all load at the beginning.

I also have two other swfs - transition.swf and writing.swf - and when you click on the writing button in the menu.swf I want to load the transition, followed by the writing.swf into the main timeline.

I am really struggling - how to you tell a button in menu.swf to do load something into main.swf from main.swf?

Thanks and best wishes,

Help: Accessing Main Timeline Var From SWF Loaded In A UILoader
Greetings enlightened ones

Here's my problem:
I have a main swf movie in which a var is defined on its main timeline. I have a UILoader on that main timeline which loads an other SWF.

Here' what I need to do: How can I let the loaded SWF in the UILoader access that variable on the main timeline of the main swf?

Please help

Accessing TextBox In MovieClip From Main Timeline
Simply put, I am unable to access the information in my input textbox from my main timeline which is embedded in a movie clip.

here's a snip of my code...

if (formOK) {
// Form processing goes here
message.from = this.nameBox_MC.nameBox_txt.text;


where nameBox_MC = instance name of movie clip which holds textbox placed on main timeline.

nameBox_txt = input textbox instance name placed on timeline of nameBox_MC.

this should make sense, otherwise I'll be more specific.

[F8] FLV/Mp3 Cue Points For Accessing Frame Labels On The Main Timeline
FLV/Mp3 Cue Points for Accessing Frame Labels on the Main Timeline in Flash 8

In Flash MX2004, creating cue points for syncing locations on flv and mp3 files to locations on the main timeline included:
1)Dragging a media component onto the stage
2)Entering file path, frame label name, and time code information in the component inspector
3)Creating the frame label names on the main timeline, and
4)Enabling the Media Labeled Frame Cue Point Navigation Behavior

Flash 8 documentation details a considerably different process of creating cue points. While it discusses how to create cue points in the flv, I have not been able to locate how to enable linking locations in flv and mp3 files with frame labels on the man timeline. It appears that there would need to be ActionScript necessary to accomplish this that is not available in the docs.

Please advise what ActionScript/process would enable this function.

Thank you!
James
kozi235@lni.wa.gov

Accessing 2nd Frame Movieclip Button From Main Timeline
I have a movieclip placed on the stage called splashScreen. Inside this movieclip i have a button called easy_btn on the second frame but every time i try and access this button from the main timeline using actionscript i get the message
TypeError: Error #1009: Cannot access a property or method of a null object reference.

I'm not sure why because i think i have referenced it properly. Here's my code -

splashScreen.easy_btn.addEventListener(MouseEvent. CLICK, chooseEasy);
function chooseEasy(evt:MouseEvent):void{
for (var i:int = 0; i < 5; i++)
{
etc.....

Can anyone help?

FLV/Mp3 Cue Points For Accessing Frame Labels On The Main Timeline In Flash 8
Hello,

In Flash MX2004, creating cue points for syncing locations on flv and mp3 files to locations on the main timeline included:
1)Dragging a media component onto the stage
2)Entering file path, frame label name, and time code information in the component inspector
3)Creating the frame label names on the main timeline, and
4)Enabling the Media Labeled Frame Cue Point Navigation Behavior

Flash 8 documentation details a considerably different process of creating cue points. While it discusses how to create cue points in the flv, I have not been able to locate how to enable linking locations in flv and mp3 files with frame labels on the man timeline. It appears that there would need to be ActionScript necessary to accomplish this that is not available in the docs.

Please advise what ActionScript/process would enable this function.

Thank you!
James
kozi235@lni.wa.gov

[FMX] Accessing Textfield In Movieclip From Its Custom Class
Hey,

Ive written a little OO code for a listitem class. I created a ListItem movieclip in the library and associated my class with it, inheriting from MovieClip:

//constructor
PlaylistItem = function(){}
//inherit from MovieClip
PlaylistItem.prototype = new MovieClip();
//register class with library object
Object.registerClass("playlistitem_mc", PlaylistItem);

This works fine. The problem arises when i try to access the dynamic textfield item thats in the "playlistitem_mc" movieclip. No matter how i reference it, i just cant get the value in or out:

PlayListItem.prototype.onRollOver = function(){
trace(this.title_txt.text);
}

This always fails.

Any ideas? Is it possible to access an object in a movieclip from a bound class? Surely it can be done...

Thanks guys, this is the greatest flash site ive found ever!
Mafro

Adding/Accessing Global-TextField In A Class
Hi Everybody,

I generally work with AS3 classes but havn't tried class stuff in AS2 much. Now i need to work this out due to some AS2 project.
I am trying to create a dynamic TextField in a Class and i want to add it on the stage and access it from all functions as well.
What i am tying is this:


ActionScript Code:
class ABC  extends TextField{            public static var loaded_txt:TextField; = new TextField();            function ABC()            {            }                            function test()            {                loaded_txt.text = "Some Text";        }}


I need loaded_txt to be added on the tage. I can't use "createTextField" as that can be done only inside a function and then it will become local but i need it global. How can that be done.Any ideas please?

Thanks!

[FMX] Accessing Textfield In Movieclip From Its Custom Class
Hey,

Ive written a little OO code for a listitem class. I created a ListItem movieclip in the library and associated my class with it, inheriting from MovieClip:

//constructor
PlaylistItem = function(){}
//inherit from MovieClip
PlaylistItem.prototype = new MovieClip();
//register class with library object
Object.registerClass("playlistitem_mc", PlaylistItem);

This works fine. The problem arises when i try to access the dynamic textfield item thats in the "playlistitem_mc" movieclip. No matter how i reference it, i just cant get the value in or out:

PlayListItem.prototype.onRollOver = function(){
trace(this.title_txt.text);
}

This always fails.

Any ideas? Is it possible to access an object in a movieclip from a bound class? Surely it can be done...

Thanks guys, this is the greatest flash site ive found ever!
Mafro

Help With Listener On Main Timeline For Custom Class
Greetings All,
I'm trying to do more and more of my projects with external classes and, along with that, creating classes for routines that I regularly do. I have a class that reads an XML file and CSS file once it's called. It has worked fine for the first few projects I used it in. With my recent project, it's not wanted to behave. The code for the class is as follows:
package {
import flash.display.Sprite;
import flash.text.StyleSheet;
import flash.events.*;
import flash.net.*;
public class fileImports extends Sprite {
public var newStyleSheet:StyleSheet = new StyleSheet();
public var newXML:XML = new XML();
public function fileImports(xmlFile:String, cssFile:String):void {
//load css file
var cssToLoad:URLRequest=new URLRequest(cssFile);
var cssLoader:URLLoader = new URLLoader;
cssLoader.load(cssToLoad);
//load xml file
var xmlToLoad:URLRequest=new URLRequest(xmlFile);
var xmlLoader:URLLoader = new URLLoader;;
xmlLoader.load(xmlToLoad);
//event listeners
xmlLoader.addEventListener(Event.COMPLETE,xmlLoade d);
cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
}
public function cssLoaded(event:Event):void {
newStyleSheet.parseCSS(event.target.data);
}
public function xmlLoaded(event:Event):void {
newXML = XML(event.target.data);
}
}
}

I am creating an instance on my main timeline with this:
var fileForThis:fileImports = new fileImports("courseInfo.xml","styles.css");

I am trying to use the data that is coming in with the XML file to populate some combo boxes. My problem is I don't know how to "listen" to the class from the main timeline to find out if the class is finished processing the XML. Right now if I try to use "fileForThis.newXML" I get a value of null. But if I put a trace on newXML in the class, it shows the content of my XML file.

I have gotten this to work on other projects because I haven't tried to use the data immediately - so the data has time to "process" before it's put into a text field, etc.

I appreciate any help I can get on this. Thanks!

Dane Williams

Getting A Class To Call A Function On The Main Timeline
Is there anyway to get an object created from a class to call a function on the main timeline? ie

main:

Code:
function tester(objectHandle:MyClass){
trace(objectHandle);
}
class:

Code:
mysterykeywordtoaccessmain.tester(this);
This possible even? Im trying to massively shortcut a destruction function by passing the stage a reference to the object which is then removed and set to null so in a sense destroying itself but from the stage.

Can't Access StaticVars Class From Main Timeline
Hi all,

Is there any reason why I can't use the StaticVars class from the main timeline? I can reference it without issue from other classes, but I always get the same error when trying from the main timeline:
1120: Access of undefined property StaticVars.


Code:
package {

class StaticVars {
public static var volumeSetting:Number = 0.5;
}
}

Code:
import StaticVars;
trace(StaticVars.volumeSetting);
Thanks for any help.

Cheers,
Rob

Difference Between Doing Things Within A Class And On The Main Timeline
after trying successfully/unsuccessfully at Class files, it seems apparent that things are sort of different when you're writing a class. One of the strangest quirks I've found is this:

in the main timeline, you can go:

Code:
var myTween:Tween = new Tween(blah blah);
myTween.onMotionFinished = function(){
something something;
};
but then when you go:

Code:
var myTween:Tween = new Tween(blah blah);
myTween.onMotionFinished = zingzang();
zingzang = function(){
something something;
};
It doesn't really work. Why? As far as I can see, zingzang is assigned a function literal, so both first and second code should be the same thing right? Just that for the second example, I had assigned the function to a variable. So what's going on?

Now in a Class file, neither approach works because you have to use the Delegate.create method to create a delegate function for the onMotionFinished event. I guess this problem comes from the fact that you can't put a function in a function when you're in a class file..

It just came accross as strange because you can't write code like you would in a class file, for the main time line.. and the a class, you can't write code like you would for the main time line.

Is It Possible To Get A Reference To The Main Timeline In An External Class?
Hello,
After spending more then 2 hours on google on how to acces the main Timeline trough an external class
i found no solution.

Does anyone know how to acces the main Timeline in an external class?
And can you acces a movieclip (the instance name) of a movie clip that is drawn on the stage and not
dynamically placed with addChild in an external class?

I hope to hear from someone.

Control Main Timeline With As3 Class File
Hello,

I'm having a problem with what should be a simple issue. Here's the problem... I have a menu btn that is created via an external class. I want to move the main timeline of my flash file to a frame label but I'm having a hard time referencing the main timeline via my external class code.

How do I control the timeline via this external class.

GotoAndStop On Main Timeline From Package / Class
Hi all,

Just signed up here. I've been having a problem for quite some time now. I've searched Google a lot (as well as here) and I can't seem to solve my problem. If this has been covered a thousand times, my apologies.

Some background: my Flash file should be usable only to logged-in users. So I pass the session ID via the params and then send out a request using URLLoader to make sure it's valid, the user has permissions, etc. The (e.g.) package that does that is this:


ActionScript Code:
package { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.IOErrorEvent; public class MyClass extends Sprite {   private var loader:URLLoader;  private var request:URLRequest;    public function MyClass(str:String) {   request = new URLRequest(str);   loader = new URLLoader();   try {    loader.load(request);   } catch (error:SecurityError) {    trace("A SecurityError has occurred.");   }   loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);   loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);  }    private function loaderCompleteHandler(event:Event):void {   MovieClip(TopLevel.root).gotoAndStop("Must Be Logged In");  }  private function errorHandler(e:IOErrorEvent):void {   trace("IE Error");  } }}


And, my TopLevel class is (h/t senocular):


ActionScript Code:
package {  import flash.display.DisplayObject; import flash.display.MovieClip; import flash.display.Stage;  public class TopLevel extends MovieClip {  public static var stage:Stage;  public static var root:DisplayObject;  public function TopLevel() {   TopLevel.stage = this.stage;   TopLevel.root = this;  } }}


I've tried the stage.dispatchEvent() and, as you can see above, the gotoAndStop(). Nothing seems to work. Also, I'm not using Scenes - I'm using Frame Labels. Any help?

How Do I Recerence Movie Clips On The Main Timeline From Inside A Class?
Hey everyone, this might be a stupid question but I thought I'd ask cause it's making me nuts. I'm all of 2 days into AS3 (coming from not using Flash at all in YEARS) so feel free to consider me ignorant. I do have plenty of application development experience in other areas though.

I can't seem to create a class that can reference an instance of a movie clip on my main timeline. I'd post code of what I've tried but I've gone through so many desperate edits & wild guesses that it was just garbled junk before I deleted it all.

Basically here's how I figured Flash could work, though maybe it doesn't work this way at all.

I'm assuming that with AS 3 being so big on being a true object oriented environment, I wouldn't need to mix my code and interface together. Preferably I'd be using the Flash authoring tools just to design my interface. Create a button... place it somewhere... give it an instance name. Roughly the equivilant of Apple's InterfaceBuilder for those of you that might be familiar with Cocoa development. I can see maybe having to put a few lines of ActionScript onto frame 1 (though really I'm hoping Flash would have a better method of kicking off the application at this point that using code tied to frames) to load my classes & such, but after that I'd like all of my code to be held in external class files.

So maybe I've got:

Interface.fla - My interface
--- Button_1
--- Button_2
--- TextField_1
Main.as - My main controller class using to handle all of my applications behavior
SomeClass.as - Some helper Class
SomeOtherClass.as - Some helper Class

Main.as would have instructions in its initialization method to go ahead & attach events to buttons & initialize anything else that needs to happen when the application starts. From there on it would all be objects communicating back & forth. Button_1 would get clicked with would fire Main.someMethod(). Main.someMethod() would then do it's thing and set the value of TextField_1. All very clean & code is very separated from interface.

Unfortunately I can't for the life of me figure out how AS3 classes reference each other like that. There doesn't seem to be any kind of a global 'root' or '_root' I can use to locate any movie clips on the stage. I've searched the help & the web for any kind of simple tutorial but to no avail. My job has tasked me with building a flash app for a project but I'd really rather not have a tone of ActionScript just shoved into frame 1. That just seems... ugh! (::shudder::)

Can someone maybe point me in the right direction here? I'm really willing to do my homework but I can't seem to locate the info I need to get started. Also, is there an ActionScript IRC channel or something maybe?

Thanks,
Cliff

How Do I Reference Movie Clips On The Main Timeline From Inside A Class?
Hey everyone, this might be a stupid question but I thought I'd ask cause it's making me nuts. I'm all of 2 days into AS3 (coming from not using Flash at all in YEARS) so feel free to consider me ignorant. I do have plenty of application development experience in other areas though.

I can't seem to create a class that can reference an instance of a movie clip on my main timeline. I'd post code of what I've tried but I've gone through so many desperate edits & wild guesses that it was just garbled junk before I deleted it all.

Basically here's how I figured Flash could work, though maybe it doesn't work this way at all.

I'm assuming that with AS 3 being so big on being a true object oriented environment, I wouldn't need to mix my code and interface together. Preferably I'd be using the Flash authoring tools just to design my interface. Create a button... place it somewhere... give it an instance name. Roughly the equivilant of Apple's InterfaceBuilder for those of you that might be familiar with Cocoa development. I can see maybe having to put a few lines of ActionScript onto frame 1 (though really I'm hoping Flash would have a better method of kicking off the application at this point that using code tied to frames) to load my classes & such, but after that I'd like all of my code to be held in external class files.

So maybe I've got:

Interface.fla - My interface
--- Button_1
--- Button_2
--- TextField_1
Main.as - My main controller class using to handle all of my applications behavior
SomeClass.as - Some helper Class
SomeOtherClass.as - Some helper Class

Main.as would have instructions in its initialization method to go ahead & attach events to buttons & initialize anything else that needs to happen when the application starts. From there on it would all be objects communicating back & forth. Button_1 would get clicked with would fire Main.someMethod(). Main.someMethod() would then do it's thing and set the value of TextField_1. All very clean & code is very separated from interface.

Unfortunately I can't for the life of me figure out how AS3 classes reference each other like that. There doesn't seem to be any kind of a global 'root' or '_root' I can use to locate any movie clips on the stage. I've searched the help & the web for any kind of simple tutorial but to no avail. My job has tasked me with building a flash app for a project but I'd really rather not have a tone of ActionScript just shoved into frame 1. That just seems... ugh! (::shudder:

Can someone maybe point me in the right direction here? I'm really willing to do my homework but I can't seem to locate the info I need to get started. Also, is there an ActionScript IRC channel or something maybe?

Thanks,
Cliff

AS3 - Call The Methods Defined In The Main Class File From Timeline Of Externally Loded Swf
Hi All,

I am new to Actionscript3.0 and the OOPs Model. It was easy to call a function on the root from the externally loaded swf using actionscript 2.0.

I want to achieve the same in ActionScript 3.0. the problem is i want to call a method defined in my Main Class which is an external .as file from the timeline of the externally loaded swf. ( eg. The externally loaded swf has got animation and when it reaches a particular frame it calls a function say a play or pause function which is defined in the main class.) how can we achieve this?

Thanks in advance

Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys

I just can't seem to solve this problem!!!

I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.

I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???

Random Class Code:


Code:

import mx.utils.Delegate;
class randomClass {

public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;

private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}

function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;

myTotal=_xml.firstChild.childNodes.length;

for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}

random_number=random(myTotal);

myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];

target_mc.title.text=myTitle;

var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);

var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}

public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}

Main Movie Code:


Code:

on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid

Any ideas???

Thanks in advance

Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys

I just can't seem to solve this problem!!!

I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.

I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???

Random Class Code:


Code:

import mx.utils.Delegate;
class randomClass {

public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;

private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}

function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;

myTotal=_xml.firstChild.childNodes.length;

for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}

random_number=random(myTotal);

myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];

target_mc.title.text=myTitle;

var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);

var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}

public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}

Main Movie Code:


Code:

on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid

Any ideas???

Thanks in advance

Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys

I just can't seem to solve this problem!!!

I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.

I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???

Random Class Code:

Code:
import mx.utils.Delegate;
class randomClass {

public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;

private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}

function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;

myTotal=_xml.firstChild.childNodes.length;

for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}

random_number=random(myTotal);

myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];

target_mc.title.text=myTitle;

var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);

var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}

public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}
Main Movie Code:


Code:
on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid

Any ideas???

Thanks in advance

Controlling A Movie Clip's Timeline Separately From Main Timeline
I've got a problem here that I've been trying to figure out for a while now, and it seems like it should be way easier than this. Here's what I've got:

I'm trying to make a neato little flash swf with lots of buttons that you can push and another little movie clip will show some little animation.

I thought I could get this done pretty simply by making a bunch of buttons, giving them an over, down, hit, sound, etc. and then having one single movie clip do all of the animations, but cleverly use stop(); and gotoandplay();

I have tried a few different ways, searched through the help & tutorials, looked all over forums on the internets, and I still can't get this to work. The main timeline is really just 1 frame, and its only purpose is to just hold all of the buttons. I have given all of the buttons instance names (ending with _btn). There is a separate layer in the main timeline for the actionscript alone, and was hoping to put all of the gotoandplay commands there. The code that I am trying to use in that frame is:


Code:
this.WV_btn.onRelease = function(){this.productzmovie_mc.gotoAndPlay(2);
};
The productzmovie_mc has a command to stop(); in the first frame, and I am trying to get a button to skip to the next frame to get it going. I put a stop(); on the last frame of that animation so that it won't run through the whole thing on the first button press. If I remove that stop(); on the first frame, the whole animation just runs whenever I test it and the button has no effect.

I thought this would be way simpler than making 25 separate movie clips and hiding them or spawning them. Does anyone know what I could be doing wrong here? This seems like a pretty simple operation, and I am probably screwing up some mundane detail (I always do that). Be gentle, I am trying to learn Flash and I am a bigtime n00b. I can post the .fla if you need to see it, but it's pretty simple so far, just lots of buttons.

Thanks!

ActionScript Differences Between Main Timeline And Movie Timeline?
Hello,

Could someone explain the difference if Action Script is on the main timeline or in a movie clips time line which is on the main timeline?

I guess I mean is with regards to referring to other items or movie clips or external scripts etc.

To try and clarify what i'm going on about....

I have a form that uses a php script. The form.swf is brought into my main movie with 'loadmovie' action script.

When the form.swf is run on its own it works. When someone enters the info and hits 'send' the form gets what it needs from the php script and then goes to a 'sucsess' frame. Great.

But..

When the form.swf is run from within my main movie and someone hits 'send' the form goes to my 'fail' frame (even though it is sending the email), the php script is returning a 'fail - invalid email entered' message to the flash form (the email was valid though!!).

Because the form.swf works on its own I'm guessing that, when loaded into the main movie, i need to add something to make it talk to the php properly.

The odd thing is that it must be talking to the php as it is sending the email!!! So why is the php sending back a 'fail' and not a 'success'.

It could be that the form.swf is just not getting a response from the php and so it going to the fail frame. In which case, if my form movie is within my main movie what do i add to the php (or action script) to receive the info to the nested movie.

I cant work it out.

Thanks soooo much for your help.

Julian

Play Movie In Timeline But Keep Main Timeline In Place
Hello,

Scenerio: You are at frame 1 of the timeline and it's stopped, you hit a button and it jumps you to frame 20 and then at frame 20 a movie clip plays.

Question. Can I have that movie play for however long I want (let's say it's a 100 frame movie) BUT have my main timeline still sit on frame 20? And then when the movie is done playing it goes to frame 21 of the main time line? Currently I have to make my main timeline be the same length as any movie I have in it, and so my main timeline ends up being an absurdly long.

Just a general answer will help - which action scripts would I be looking to use (I'm using Flash 8 Pro)?

Thanks

Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.

Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).

I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.

The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?


ActionScript Code:
package a {
     public class Alpha {
          public function Alpha() {
               x:Bravo = new Bravo();
          }
     }
}

package a {
     public class Bravo {
          public function Bravo() {
               this.addEventListener(MouseEvent:CLICK, clickEvt);

               function clickEvt(event:MouseEvent) {
                    <MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
               }
          }
     }
}

Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...

In my classfile class Classes.tools.depthManager, I've got a static methode


Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode


Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."

So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write


Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."

I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...

Any ideas? Thanks!

Movie Clip Timeline Vs. Main Timeline
Ok, i have made a movie clip in Swift 3d and have imported it into Flash MX. Now it is in the first frame as flash will place it there and what i would like to have happen is to tell frame 1 that when the movie clip's timeline ends and stops(frame 90) to then move the parent timeline to continue with stuff
If any one reads this please help or refer me to a MX book that is worth the valuble time we think we have!
Mike

Movie Symbol Timeline & The Main Timeline
Hi guys,

There is the frame in my main timeline which has a movie symbol and when the timeline heads reaches & stops at this frame & start playing the movie symbol timeline, i want that when the timeline head reaches at the end frame of the movie symbol timeline, it should take me to the any frame number/label of the main timeline i want.

I tried adding the action to the end frame of the movie symbol to take me to a different frame of the main timeline but it doesn't do anything. It remains at the same frame of the main timeline.

Is there any way out?

Regards, Rohit

Accessing Document Class From Static Class?
I am building a family tree like tree in flash.

I have a package TreeManager which holds all my classes.

The document class TreeManaager.Tree controls adding new nodes to the stage.


ActionScript Code:
public function addProfile(relationship:Object):void
{
    profile = new Profile();// create new profile

    var align:Alignment = new Alignment();//make Alignment object
...

The profile class controls all the internal node functionality.

Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?


ActionScript Code:
public class Profile extends MovieClip {
       
public function Profile ():cool:
{
    this.addEventListener(MouseEvent.CLICK,Tree.addProfile);

This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?


ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);

Reload Main Class From Within Main Class?
I'd like to just start my whole main class over again if certain conditions arise. The monitoring of those conditions takes place *within* the main class. Is there any way to just tell that class to reload itself -- to call its own constructor -- essentially starting the whole thing from scratch? I found references to doing it the old way -- jumping back the first frame of the main timeline, for instance -- but I'd like to do it in a more OO/AS3 sort of way.

Thanks.

Loading A Movie From A Movie On Main Timeline, To A Specific Frame On Main Time Line
I need help loading a movie from a button in a movie on the main timeline. To a specific frame on the main timeline.
i.e. I have a navigation movie, in it is a load of buttons. I want to load separate movies to a blank movie on a specific frame on the main timeline.
I guess I am having target problems, I can load the movie in the main timeline, but not the frame i want it or the the blank movie in that frame.

Calling A Function In Main Class From A Loaded Swfs Document Class
Hi
I have a main.swf that loads page.swf. They each have a document class called "Main" and "Page".

How can I call a function in Main from Page?

In AS2 this would be somthing like _parent.myFunction();


Cheers

Accessing Main MovieClip
Hello all!

I've got some newbie questions I hope you can answer me:

1. I'm builiding a control library from flex,but I don't know how to interact with the main window (I explain):

I create something.as, suppose I've create a constructor witch draw a rectangle to certain part of the screen. How can I use the addChild method from this class. I've tried to pass the "main movieclip" to the constructor but seems forbidden.

2. Will I be able to reuse my controls from flash?

3 and last. Can I built websites from Flex????

Thank you for your patiente

See you Later!

How To Control The Main Timeline From An MC Timeline?
May an action in a movie clip's timeline or within an OnClipEvent target the scene's main timeline, say, forcing the swf to go to its third frame, for example? Thanks for any idea.
P.S. Actionscript 1.0

Main Timeline Vs Mc Timeline Smackdown
I've made a little animation in a mc several instances of which sit looping on the main timeline.
I want these mcs to load at intervals on the main timeline, frame 1, 5, 10 etc. (a kind of twinkling stars thing if you must know.)
The problem is the main timeline overrides the mc's timeline.
I was able to sort of fix this by shortening the main timeline, but I can see this solution is not satisfactory for any number of reasons, and even at the most basic level it seems erratic.
Obviously my understanding of this issue is too theoretical and not practical enough, or the other way around.
How can I force the main timeline to really accept the mc timeline instead of just pretending to?

A Value From The Main-timeline To A Moviclips Timeline
Hi!
I have a movieclip on the scene. I also have a button on the scene and when I press the button I want to send a variable-value to the movieclip. I have a variable set in the actual frame on the main-timeline but the movieclip doesn´t catch that, when traced I get undefined. Can I send a value from the main-timeline to a moviclips timeline?

Copyright © 2005-08 www.BigResource.com, All rights reserved