LoadMovie And OnLoad Functions
I'm trying to create a system which does a simple loadMovie function
on (release){ _root.loadMovie("rework.swf"); }
and in that movie rework I have a onLoad Function which doesn't want to run:
onLoad = function (success) { _root.Button1Position = 1; _root.Button2Position = 2; _root.Button3Position = 3; _root.Button4Position = 4; _root.Button5Position = 5; _root.growth_counter = 0; _root.movement = 0; _root.Button1.gotoAndStop(10); _root.Button2.gotoAndStop(5); _root.Button3.gotoAndStop(1); _root.Button4.gotoAndStop(15); _root.Button5.gotoAndStop(20); _root.movement2 = 0; };
Now this LoadFunction sets up the move so that it is running right, and when I just open it normally it runs fine, but if I open it within another Movie file, it doesn't run at all. Am I missing something?
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 06-28-2006, 03:18 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Using Two Or More Onload Functions
Hello everyone.
I just started to learn actionscripting in Flash and now ran into some problems.
Hopefully you can help me out
How to use two different LoadVars() objects in one page.
For example, I have:
PHP Code:
info = new LoadVars();
required = 12345
info.load("http://localhost/kiosk/result.php?cd="+required,POST);
info.onLoad = function() {
cd_artist.text = this.cd_artist;
}
and second one also on the same page:
PHP Code:
c.load("http://localhost/kiosk/read_files.php",POST);
c.onLoad = function(success) {
songs = c.listing.split("@");
...etc
}
What happens now, is that first is displayd info from info.onload function and then c.onload function but info is discarded. How to make this code work so both functions are displayd same time.
OnEnterFrame / OnLoad Functions
question about the .onLoad and .onEnterFrame functions.
if i assign any of them this way : this.onLoad for instance ;whatever is instructed in the function works just fine when previewing the swf.but if i load that swf in another movie ,inside a target called "content" , do i have to call the function like this: _root.content.onLoad ... ? because it doesn't seem to work. hope this makes sens
Combining Two OnLoad Functions
Hey there all!
Is it possible to combine two onLoad functions into one? Please have a look at the code in questions below. Thanks!
Code:
loadFiles.onLoad = function(success:Boolean) {
if (success) {
total = this["total"];
setInterval(Delegate.create(this, loadImageLeft), 2000);
setInterval(Delegate.create(this,loadImageRight), 3500);
if((x == total) || (y == total)) {
x = 0;
y = 5;
}
} else {
trace("Error loading/parsing LoadVars.");
}
}
loadVertFiles.onLoad = function(success:Boolean) {
if (success) {
totalv = this["total"];
setInterval(Delegate.create(this, loadVertImageLeft), 2500);
setInterval(Delegate.create(this, loadVertImageRight), 3000);
} else {
trace("Error loading/parsing LoadVars.");
}
}
loadFiles.load("http://www.volume4.com/kb/banner_mod/get_files.php?dir=horiz");
loadVertFiles.load("http://www.volume4.com/kb/banner_mod/get_files.php?dir=vert");
Two OnLoad Functions On One Page...
Hello.
I am trying to call two different onLoad functions to work on the same page. The problem is when second one is loaded,
texfield text called from first onLoad function disappears. I want both appear on the screen same time.
Here's the code:
This should display text in textFields.
PHP Code:
required = 12345;
info.load("http://localhost/kiosk/result.php
cd="+required,POST);
info.onLoad = function() {
cd_artist.text = this.cd_artist;
cd_album.text = this.cd_album;
cd_genre.text = this.cd_genre;
}
This should get variables from php and then draw some graphical objects.
PHP Code:
c.load("http://localhost/kiosk/read_files.php",POST);
c.onLoad = function(success) {
songs = c.listing.split("@");
....
}
Both these piece of codes are on the same layer.
[F8] Problem With Xml.onLoad And Functions Not Being Called
I'm having a problem with the following code.
I want the constructor of the class sample to make an xml request to the server. It will get back a url_id which will be assigned in the onLoad function. There is another function poll which sends the url_id to the server every ten seconds. This is essentially a heartbeat function and uses setInterval to delay the sending of the xml request. If I use poll in the constructor, it appears to never get called based upon trace statements and if I use it in the timeline, the url_id value is undefined. See code. Thanks for any help.
On the timeline in frame 1, I have:
Code:
stop();
var sample:Sample;
sample=new Sample();
I have also tried putting poll in the timeline (see question 2 below for sample code).
problem code:
Code:
class Sample{
public function Sample(url_id){
this.url_id=url_id;
trace("this.url_id in constructor is " + this.url_id);
var xml_str:String;
var interval_id:Number;
//session_id request and response
var session_request_xml:XML;
var session_response_xml:XML;
trace('in constructor');
//this.img_upload=new ImageUpload("hello");
xml_str="<actions><action name='get_new_url_id' /></actions>";
session_request_xml=new XML(xml_str);
session_response_xml=new XML();
session_request_xml.contentType="text/xml";
session_request_xml.sendAndLoad("http://server.com/flash_api/send_basic.php", session_response_xml);
// loads back
//<?xml version='1.0'?><results><result name="url_id">md5</result></results>
session_response_xml.onLoad=function(){
trace("this loaded");
trace(session_response_xml.toString());
url_id=session_response_xml.childNodes[0].childNodes[0].childNodes[0].nodeValue;
trace("url_id " + url_id);
this.url_id=url_id;
trace("url_id in constructor is " + this.url_id);
//this doesn't get called
this.sayHello();
//this was never getting called
setInterval(this.poll,10000);
}
}
public function poll(){
trace("in poll this.url_id " + this.url_id);
//poll request and response
var poll_request_xml:XML;
var poll_response_xml:XML;
var xml_str:String;
xml_str="<actions><action name='keepalive' url_id='"+ this.url_id + "' /></actions>";
trace(xml_str);
poll_request_xml=new XML(xml_str);
poll_response_xml=new XML();
poll_request_xml.contentType="text/xml";
//setInterval(poll_call,30000,poll_request_xml, poll_response_xml);
poll_request_xml.sendAndLoad("http://server.com/flash_api/send_basic.php", poll_response_xml);
poll_response_xml.onLoad=function(){
trace("the poll loaded");
trace(poll_response_xml.toString());
}
public function sayHello(){
trace("sayHello");
}
}
Based upon the onLoad docs and mook book, it seems that onLoad should only be called after XML has fully loaded and been parsed. Based upon trace statements, this appears correct.
I have the following questions:
1. why aren't the functions (setInterval... , sayHello) in the onLoad event called in the constructor? Based upon desc in docs, they should be.
2. if i change the timeline code to:
Code:
var sample:Sample;
sample=new Sample();
setInterval(sample.poll, 10000);
why is the url_id value in poll "undefined" when I trace it? It should be set to the url_id in the constructor returned from the server? The 5 second delay should allow for this to be set.
thanks for any help.
y
Can't Call Functions Inside Xml Onload
Hi, I have a class
Code:
class test
{
function test()
{
trace("test1");
this.init();
}
function init()
{
trace("test2");
var temp:Function = this.func1;
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(success)
{
if (success)
{
trace("test3");
temp();
}
}
xml.load("game.xml");
}
function func1()
{
trace("test4");
this.func2();
}
function func2()
{
trace("test5");
}
}
When I run the program the trace("test5") in func2() is never called. Why is this so? Any suggestions?
Help Loadmovie And Onload
I have a URL Query String Generated Flash Site and I need this code so that when it can not find the swf typed it will return with an Error. Here's my code that I thinks should work.
Code:
loader1.onLoad = function() {
if (success) {
pagetxt.text = ("Page Found");
} else {
pagetxt.text = ("File Not Found");
}
};
Onload And Loadmovie
ok, I have a mc called imageWindow. I'm loading jpegs into the imageWindow using loadmovie. This bit works fine.
The problem is that I want to be able to read the new image's height and width as soon as it's loaded. I've tried two approaches:
imageWindow.loadMovie("images/" + filename);
myHeight = imageWindow._height;
myWidth = imageWindow._width;
This doesn't work because I access the _height property before the jpg has loaded.
imageWindow.onLoad = function() {
myHeight = imageWindow._height;
myWidth = imageWindow._width;
}
imageWindow.loadMovie("images/" + filename);
This doesn't work because the onLoad handler doesn't get called.
imageWindow.loadMovie("images/" + filename);
imageWindow.onLoad = function() {
myHeight = imageWindow._height;
myWidth = imageWindow._width;
}
This doesn't work for the same reason.
Any ideas?
OnLoad And LoadMovie
I have a URL Query String Generated Flash Site and I need this code so that when it can not find the swf typed it will return with an Error. Here's my code that I thinks should work.
loader1.onLoad = function() {
if (success) {
pagetxt.text = ("Page Found");
} else {
pagetxt.text = ("File Not Found");
}
};
Help LoadMovie And Onload
I have a URL Query String Generated Flash Site and I need this code so that when it can not find the swf typed it will return with an Error. Here's my code that I thinks should work.
Quote:
loader1.onLoad = function() {
if (success) {
pagetxt.text = ("page Found")
} else {
pagetxt.text = ("File Not Found");
}
};
LoadMovie OnLoad?
Hy guys.
I have searched the forum, but i cant find anything that gives me a answer on the following.
I have a MC within a other MC.
the first MC has this code.
onClipEvent(load) {
loadMovie(portImg1, this);
loadMovie.onLoad = function() {
_root.port.gotoAndStop(14);
}
}
so, after the image loads i want the parent MC to go and hold at frame 14.
can someone help me out. please?
greets,
Fregl
Using OnLoad In Conjunction With LoadMovie()
If I have a clip called hold_mc on the main Time Line that uses a loadMovie() clip method to load in a swf containing a clip called movie_mc how would I use the onLoad clip call back event to perform some action in the main movie. ie:
Would I put the following action within the on the onRelease mouse event that triggered the loading of the swf;
hold_mc.onLoad= some function();
or
do I put it on the clip to be loaded
this. Onload=some function?
How would I also go about addressing the loaded clip is it level1.moviemc.somecallback=somefunction
Thanks for any help.
Confused About OnLoad And LoadMovie - Help
I'm creating my first full Flash website and am very new to Actionscript. Everything is coming together well except for my intro. I have an intro splash movie clip which I want to load into an empty "master" movie clip. In that intro splash movie clip is a button which gives the user the option of skipping the movie. Here is how I currently have the main stage set up:
Frame 1:
• layer with empty movie clip and instance name LoaderClip
• actions layer with this code:
onLoad = function(){
LoaderClip.loadMovie("intro.swf");
}
Frame 2:
• layer with preloader artwork
• actions layer with this code:
stop();
myInterval = setInterval(preloader,100);
//preloader
function preloader(){
if(getBytesLoaded()>= getBytesTotal()){
play();
clearInterval(myInterval)
}
//controls dynamic text box
myText.text=Math.round(getBytesLoaded()/getBytesTotal()*100)+"%";
//scales the mask in the bar movieclip
bar.mask._xscale = (getBytesLoaded()/getBytesTotal()*100);
}
Frame 3:
• layer with splash intro movie clip
• actions layer with stop();
I have set up a button within the intro splash movie clip (on frame 3) which allows users to skip the movie. I've given it the instance name skipButton. The code I've used for that button is:
skipButton.onRelease = function(){
LoaderClip.loadMovie("home.swf")
}
The problem is that the button doesn't work and I cannot figure out what I've done wrong. Help! Oh, and I'm using Actionscript 2.0 and Flash CS3.
LoadMovie OnLoad Event?
I am loading in jpgs dynamically.
my question is.... IS there a way to trigger an event when the picture has been fully downloaded?
Code:
picContainer.loadMovie("myPicture.jpg");
picContainer.onLoad = function(ok)
{
if(ok)
{
trace("loaded!!!");
}
else trace("you obviously don't have a clue what you're doing");
}
this code does not work... at least as far as I know...
HOW can I trigger this event?
in the past i've simply done on onEnterFrame check to see if the width of the container was bigger than 3 pixels and then delete the onEnterFrame function hahaha. it's super ghetto, but it has worked for me, for years.
I wish to do things a better way, so any help you can provide is greatly appreciated!
LoadMovie() & XML.onLoad Query(AS2)
Hi all :)
I have a Flash file that uses the loadMovie () to load JPG files successfully, example:
imageuri = "../images/00_proto" + var1 + ".jpg";
holder_mc.holder0.loadMovie(this["imageuri"]);
Working Example
'holder_mc' is the container clip and 'holder0' is the clip that stores the loaded JPG file, this works fine.
I am upgrading the Flash file using an XML database, code example:
var statesXML:XML = new XML();
statesXML.ignoreWhite = true;
statesXML.load("../XML/USA.xml");
statesXML.onLoad = function(success)
{
// XML loading excluded
// Problem code
imageuri = "../images/00_proto" + var1 + ".jpg";
_parent.holder_mc.holder0.loadMovie(this["imageuri"]);
}
The JPG's are not being loaded into the 'holder0' clip from inside the XML.onLoad() method. Spent hours trying to fix this, still have not resolved the problem. Any responses much welcomed!
regards
John
www.javono.com
LoadMovie OnLoad Not Working
I've got a button that loads an image into a container called myloader.
I'm using this actionscript:
ActionScript Code:
on (release){ _root.myloader.loadMovie("2.jpg");_root.myloader.onLoad = function(success) {trace ("loaded");}}
The image loads but nothing traces in the output - whats going wrong?
OnLoad Not Working For Clip Using LoadMovie
The 'hold' movieClip is created using the createEmptyMovieClip command. Using the code below, the movie gets loaded but the onLoad function doesn't execute. Any ideas?
this.createEmptyMovieClip("hold",0);
hold.onLoad = function() {
trace("onLoad");
advanceQueue();
};
function startQueue() {
loadMovie(loadQueue[qIndex], "hold");
}
Executable Files With A LoadMovie/onLoad
I tried posting this before on this thread here. But I got no responses. So let me try to explain the problem further, hopefully, someone has run into this problem before.
I am trying to load a jpg into a movie clip, so it can be a thumbnail for a photoalbum. I do not want the images to be in the fla file because it will be too big. So I am using loadMovie to load the jpg files into my project. I also know I need an onLoad event action to then call onRelease statements to the movie clip once that jpg has been loaded. Now if I test my movie in simulate download mode, the project loads fine, my onLoad reacts and I can get my button action called. But if I just hit control enter or publish to an exe file, the button action never gets called, it is like Flash is ignoring the onLoad statement, wouldn't it still try to access this code in some way, my code is on the link above if you need to see it. Thanks for your help in advance.
LoadMovie Not Working Inside XmlData.onLoad()
I'm successfully reading in values from an XML file which I would like to use to load images. I have no trouble loading the images if i assign the URL strings in the frame's actionscript manually. however, if i attempt it from the xmlData.onLoad() function, nothing seems to happen.
//works
sCoverImageURL_1 = "http://www.google.com/intl/en_ALL/images/logo.gif";
loadMovie(sCoverImageURL_1,"mvSwapCover1");
//doesn't
function loadXML(loaded) {
if (loaded) {
.....misc XML loading, works
loadMovie(sCoverImageURL_1,"mvSwapCover1");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("five.xml");
Flash, Mozilla (family), OnLoad, LoadMovie --> Bug
Hey
On my new website, I have a problem with every browser except for IE (I tested it out with Netscape 6, 7, Mozilla, Firefox and Opera). The preloader which loads the swfs in my main swf gets stuck at 0%.
I searched and searched for an answer and all I found is this german page on another forum that I translated. It talks about a problem related to the onLoad function in Flash using non-IE browsers. There's also an example if u scroll through the page.
Now, I don't even have an onLoad function in my swfs. All I have are some loadMovies. BTW, there's only one preloader (in my main swf) for every movie that I load. Its similar to this, but the code isn't the same: http://www.kirupa.com/developer/mx/p...transition.htm.
Did someone else already run into theses problems? Can someone help me out?
Thanks.
OnLoad Event For Movie Clip Loaded With LoadMovie
Here is a basic one (I think).
I load a movie to a pre-existing clip like this.
<i>loadMovie("redcircle.swf",_root.myClip);</i>
..And it works very well. No prob there.
but when I call
<i>_root.myClip.gotoAndPlay(2);</i>
then myClip wont play frame 2.
If put the gotoAndPlay action under a button and wait
just a little while before pushing it then
it plays as it should. So I think there is a delay
while it is loading that makes it impossible to play
a frame in myClip right after I call loadMovie.
<b>My question is</b>: How do I tell my movie to wait until
redcircle.swf has been fully loaded into myClip and
then try to call gotoAndPlay?
Question About Execute Order Of Functions And "onLoad"
help! I am having a hard time understanding the way orders are executed in flash.
Code:
var myPrintJob:PrintJob;
function fPrint(){
//create PrintJob object
myPrintJob = new PrintJob();
//display print dialog box
myPrintJob.start();
fPrintText();
fPrintNotes();
fPrintImages();
//send the job from the spooler to the printer
myPrintJob.send();
//clean up
delete myPrintJob;
}
//
fPrintText(){
printArea_mc.myPrintText_txt = "Hello World";
}
fPrintNotes(){
printArea_mc.myPrintText_txt = "Good Bye World";
}
fPrintImages(){
printArea_mc.myPrintText_txt = "Image Caption";
printArea_mc.print_ldr.contentPath = "images/myImage.jpg";
}
printArea_mc.myPrintText_txt.onChanged = function(evtObj) {
trace(evtObj._name+" changed");
myPrintJob.addPage("printArea_mc", {xMin:-36, xMax:612, yMin:-36, yMax:810}, {printAsBitmap:true});
}
//
The problem is that the "myPrintJob.send()" executed BEFORE the addPage in the "onChange" listener. How can i make fPrint() wait to execute the next line untill AFTER the "onChange" pops?
This is a problem that I have all the time with Flash. I have a function, and at a specific poit in need to load somehing in ... populate a .txt field, load and image, load some xml ... and then when that is done continue on with the rest of the function. How can i do that? I have tried so amny diferent ways. Any ideas?
--MM
LoadMovie And Functions
Is there any way to use .swf movies with Loadmovie, and still have their User Defined Functions accesible from other Loaded SWFs? instead of having to keep all the movies with functions in one SWF?
Loadmovie, Functions As Objects, And XML
Ok, here's the deal:
I've got an swf that's the project interface. This movie loads other movies that actually do stuff. I'm stuck on the movie loading into level1. This movie works fine by itself, but breaks when I load it into the interface. After some grueling testing, I've found the problem. Using a tutorial on XML from MM, I created the following code:
MessageXML = new XML();
MessageElement = MessageXML.createElement("LOGIN");
MessageElement.attributes.sessionID = _root.sessionID;
MessageXML.appendChild(MessageElement);
MessageElement = null;
trace ("message out: " add MessageXML);
MessageReplyXML = new XML();
MessageReplyXML.onLoad = onMessageReply;
MessageXML.sendAndLoad(url, MessageReplyXML);
MessageXML = null;
The message out is being sent fine. The problem lies with the onMessageReply function:
function onMessageReply () {
trace ("new message: " + MessageReplyXML);
if (MessageReplyXML.hasChildNodes()) {
trace ("test");
mControl.run = mControl.onMessageReply;
}
}
When loaded into level1, onMessageReply executes, but it doesn't see the MessageReplyXML variable. I can specify it like this:
if (_level1.MessageReplyXML.hasChildNodes()) {
trace ("test");
_level1.mControl.run = _level1.mControl.onMessageReply;
}
But then I can't run it on its own. I tried using _root instead of _level1, but it still doesn't work. Has anyone had any problems like this? Any help is GREATLY appreciated.
Working With Loadmovie Functions
I have a problem with loading external movies in Flash. For example. When I click the homepage link, it will load properly, but when I click another link, it loads other other movie over it. I put unload actions to the previous movie but it doesn' disappear when its supposed to. Can somebody check the source file and help? Thanks.
*Please note that I only configured the first three links to work...
Home, portfolio, and projects...
Because size is an issue on Flashkit, the file is located here
http://www.dabandits.com/site.zip
Working With Loadmovie Functions
I have a problem with loading external movies in Flash. For example. When I click the homepage link, it will load properly, but when I click another link, it loads other other movie over it. I put unload actions to the previous movie but it doesn' disappear when its supposed to. Can somebody check the source file and help? Thanks.
*Please note that I only configured the first three links to work...
Home, portfolio, and projects...
Because size is an issue on Flashkit, the file is located here
http://www.dabandits.com/site.zip
LoadMovie Messing Up Functions
The preloader and the page I want to load are both in the same .fla. Loader on frame 1 and page being loaded on frame 2. Now this .swf file loads and functions properly. Here is the code I use in frame 1 of the preloader:
preloadtext.onEnterFrame = function () {
loaded = this._parent.getBytesLoaded ();
total = this._parent.getBytesTotal ();
percent = ((loaded / total) * 100);
trace ("Percent: " + percent);
percentage = (int (percent) + "%");
preloadtext.percent_txt.text = percentage;
mxbox.gotoAndPlay((20*(percent/100)));
if (percent == 100) {
gotoAndPlay (2);
}
}
However, I have a container that starts the preloader. It has a blank movie clip and this code on a seperate layer:
stop();
mc_container.loadMovie("main.swf");
When I use this .swf file to go to the page I want there are problems such as certain functions don't work (drawing lines, resizing pictures). Sometimes buttons don't even work. I really don't know what to do. Thank you.
LoadMovie Special Functions
How could I use loadMovie command to load an external swf file and have the external swf file's action script functional in the parent movie. If I use LoadMovie to load into an empty Movie Clip with _root, only the animation works. Thank you for your help
Is LoadMovie AS Messing Up My Functions?
i will try to explain as best I can. I'll post my fla.
here is my .fla
www.zunskigraphics.com/showme/index.fla
In my timeline i have 8 buttons
Each button has an instance name of RWone_mc
Each button also has the AS of:
ActionScript Code:
on (release) {
loadMovie("rw1.swf", (2));
}
NOTE:: Above is for the first button. Obviously each button has an instance name of RW"thebuttonnumber" and loads the rw'buttonnumber.swf"
I have also in the first frame of the actions layer the following AS for each button (just a simple rollover technique for _mc's to act like _btn's)
ActionScript Code:
this.RWone_mc.onRollOver = function() {
RWone_mc.gotoAndPlay("_over");
};
this.RWone_mc.onRollOut = function() {
RWone_mc.gotoAndPlay("_out");
};
this.RWtwo_mc.onRollOver = function() {
RWtwo_mc.gotoAndPlay("_over");
};
this.RWtwo_mc.onRollOut = function() {
RWtwo_mc.gotoAndPlay("_out");
};
this.RWthree_mc.onRollOver = function() {
RWthree_mc.gotoAndPlay("_over");
};
this.RWthree_mc.onRollOut = function() {
RWthree_mc.gotoAndPlay("_out");
};
this.RWfour_mc.onRollOver = function() {
RWfour_mc.gotoAndPlay("_over");
};
this.RWfour_mc.onRollOut = function() {
RWfour_mc.gotoAndPlay("_out");
};
this.RWfive_mc.onRollOver = function() {
RWfive_mc.gotoAndPlay("_over");
};
this.RWfive_mc.onRollOut = function() {
RWfive_mc.gotoAndPlay("_out");
};
this.Rsix_mc.onRollOver = function() {
RWsix_mc.gotoAndPlay("_over");
};
this.RWsix_mc.onRollOut = function() {
RWsix_mc.gotoAndPlay("_out");
};
this.RWseven_mc.onRollOver = function() {
RWseven_mc.gotoAndPlay("_over");
};
this.RWseven_mc.onRollOut = function() {
RWseven_mc.gotoAndPlay("_out");
};
this.RWeight_mc.onRollOver = function() {
RWeight_mc.gotoAndPlay("_over");
};
this.RWeight_mc.onRollOut = function() {
RWeight_mc.gotoAndPlay("_out");
};
In the actions layer about 20 frames later, I call for a movie in another spot with this AS
ActionScript Code:
loadMovie("soundon.swf" , (4));
Now, what I am having trouble with is the rollOver status of each movieclip. It worked fine before I did the AS for the soundon button. Is this due to the way I call it? loadMovie vs. loadMovieNum ???
I don't get it!!!
Please Help!!!
see the example here
www.zunskigraphics.com/showme/index.swf
Thanks!!
ZG
LoadMovie Callback Functions?
I'm building a modular flash shell for a client and it loads all of the content from external sources, particularly the swf files for content. If the specified file does not exist I would like it to load an internal file instead, but I can't find any sort of callback to the loadMovie method. Do anyone know a way of checking whether a loadMovie call failed or succeeded?
Cookies for all who answer.
_root.loadMovie And _global Functions
If I load a new swf into the root with _root.loadMovie my _global functions and variables should still be there shouldn't they?
I would have thought so but it doesn't seem to be the case.
Thanks for amy help.
Why Does LoadMovie Push Functions To _root?
I posted this over at Kirupa, but didn't find an answer. Basically I want to know why Flash, when loading external swf's that contain looping functions(such as for a timeline, or anything constantly updated), the second swf loaded seems to push the functions from the first to the _root level. I'll attach a zip with example files, but let me explain more first:
I have my main flash file that has 2 buttons and a container MC named "contentclip". The first button has this code:
on (release) {
contentclip.loadMovie("Loader1.swf", "contentclip");
}
and the second, this code:
on (release) {
contentclip.loadMovie("Loader2.swf", "contentclip");
}
Now, say I have the two external flash files named Loader1.swf and Loader2.swf. One has the following function:
fruitbowl = function() {
apples = "36"
}
setInterval(fruitbowl,20)
and the second has no function at all.
What happens is that when I click on the first button, things load normally. If I click it again, OR if I click on the second button, the variable "apples" gets pushed to level0 (_root). Why? Thanks so much guys, I'm trying hard to figure this one out, but its stumping me.
Here's the file: http://www.netonup.com/echelon/FlashCourse.zip
Setting Properties And Calling Functions After Loadmovie
I have a series of external .swf files that I want to load into a container movieclip on my top level timeline using Flash MX and AS1. I'm quite happy doing this using loadmovie and checking getBytesLoaded and getBytesTotal to determine when it's loaded using a setInterval function.
What I would like are some suggestions to solve the following problems:
1. I have a number of top level timeline defined variables that I would like to use to create custom properties on the container movieclip into which I am loading the external .swf files. I'd rather not write code in each external .swf to access these directly from the _parent timeline because I may change the relative location of these variables at some point in the future. I would also prefer not to use the _global namespace either as it is too difficult to manage effectively. My preferred approach would be to write some code on the top level timeline to assign the properties to the container movieclip at an appropriate time for the external .swf access in frame 1. One approach I have tried is adding a query string to the end of the loadmovie URL but this has the problem that it doesn't work when running the movie through the standalone Flash player which will impact our development turnaround. Are there any other techniques which will allow me to create the timeline variables in the container movieclip before the code in frame 1 is executed?
2. The external .swf files that I am loading are single frame movies and have a number of timeline functions defined in them in the first frame that I would like to call from the top level timeline. As far as I understand it these functions are not defined until the playhead of the movieclip's time line has passed through the first frame once.
One approach I have tried is to check if the functions are defined before I call them. This works but is not a generic solution since the external movies have a range of different functions with no common functions between them all. Again I'd rather not write any code in the external .swf files that ties them into the environment into which they are being loaded in case this changes in the future.
Another solution that I have tried is adding this code to the top level timeline:
MovieClip.prototype.onEnterFrame = function() {
this.onEnterFrame = null;
this.movieLoaded = true;
};
and then checking for the movieLoaded property on the container movieclip in a setInterval function prior to calling the functions. As I understand it the prototype defined onEnterFrame function is executed as the playhead enters frame 1 and is then set to null. When the movieLoaded property is true I can be sure that the playhead has passed through the 1st frame at least once. Any onEnterFrame functions defined in frame 1 are not affected by this code as their definition happens during frame 1 and is only current on the second onEnterFrame event. This approach falls down if there is an onEnterFrame event defined in the external .swf files in a #initclip block which would be executed before frame1. In my case I know is not true but I am seeking a general solution. Any other ideas?
Thanks for your help in advance.
Martin.
Variables/functions "pushed" To Level0 On LoadMovie
I posted this in the Flash8 forum, but I guess this is the right forum for this question:
Hey guys!
I'm trying to get an interface that will load external MCs that contain timeline control functions in them. Basically these are long "topics" that currently interface through a web content program - I would like to unify them into a single flash-based interface, but the functions that are in the external flash files, such as this:
dwnLine = function () {
totalBytes = getBytesTotal();
loadedBytes = getBytesLoaded();
percentDone = (loadedBytes/totalBytes)*100;
percentDoneRd = Math.round(percentDone);
setProperty("timeline.progLine.loadLine", _xscale, percentDoneRd);
};
get pushed to level0 when you load the next MC, instead of just being deleted with the old MC. I've tried creating a function on the root timeline to delete the variable and the specific function names, but its not working, it just fights with the phantom functions endlessly creating/deleting the variables. This is turn screws up the timeline in the new MC that was loaded. Does anyone know why/what Flash is doing here? If I knew the reason it was being pushed up to level0 I could stop it, but I'm a bit lost. Thanks, lemme know if you need more info or a sample to answer!
-Anthony
PS: I'm using a simple
on (release) {
loadMovie ("Loader1.swf", "/contentclip");
}
to load the new MCs into a container MC called "contentclip"
XML Loads Other XML Files, Onload Function In Onload Function
I am writting an image gallery that loads one intial xml file named galleries.xml.
From this point each xml node loads a XMl file for that gallery that holds all the images.
The problem arises in the fact that to do this I need a onload function within an onload function. Onload functions dont accept parameters so I can pass down the variable that shows what loop the gallery loop is on as I need that in the function that holds the images. I hope you can understand what I am trying to say.
I will include the galleries.xml file and a sample image xml file and the fla.
Dynamic Functions - Creating Functions At Runtime Without So Many Ifs/elses...
Hi, nice to register after lurking for a while and seeing how smart people are on here......
I am writing some code that needs to be very efficient, yet flexible. This is in a class and when the class gets initialized a function is setup. I want this function to run straight through without doing any time-consuming things such as calling other functions or routines, or doing any if/else logic/branching.
Now I know that you can setup a function at anytime during runtime such as:
Code:
var myFunction:Function = function() {trace('HELLO!')}
But what I am trying to do is to try and append code to a function based on logic, yet I don't want the function to be deciding this logic when it is running as it will only need deciding when the function is created.... imagine if it were a string it would be something like myFunction+="do somethingelse;" which would be the same as having initially setup myFunction as such:
Code:
var myFunction = function() {do something; do somethingelse;}
With this I seem to be having no luck
Here's an example where I setup the most compact/efficient function at runtime depending on what I want the function to do. Now this was fairly simple because when we create the function there are only a few possible variations, but I need someway of doing a function+= as my real code has quite a few variations and it would be a nightmare have a zillion if/else branches. REMEMBER I do not want any logic/decisions in the function itself as it to be the most efficient the function must be as compact as possible and run straight-through.
Code:
var dynamicFunction:Function;
//
// Setup the dynamic function & call it
// In this example outputs "Hello Jim" & "Goodbye Jim"
dynamicFunction = CrapSetupRoutine(true, true, "Jim");
dynamicFunction();
//
// Try and setup the dynamic function using a less ify/elsey (less complicated) routine & call it
// In this example it doesn't work if we try and make it say both Hello & Goodbye like above :(
dynamicFunction = SetupRoutineIWouldLike(true, true, "Jim");
dynamicFunction();
//
function CrapSetupRoutine(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// Far too many ifs/elses...but remember the function created cannot have any if/else logic or calls to other functions
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else if (sayHello and sayGoodbye) {
returnFunction = function () {
trace("Hello "+yourName);
trace("Goodbye "+yourName);
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
} else {
returnFunction = function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
//
//What I actually want the Setup function to resemble is this
function SetupRoutineIWouldLike(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// the ifs/elses are as minimal as possible, which is good
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
}
if (sayGoodbye) {
// the += below doesn't work.....so the question is how to append to it?????
returnFunction += function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
// The end
P.S. I knew the += would never work as this is a function and not a string. But at least if you think of the function as a string you'll get what I'm trying to do.....I suspect if it can be done it involves casting or something and maybe using strings initially??
Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.
For example, here I am trying to set the private boolean member variable to the state of the checkbox.
//NOTE: This is an EventListener. Does this change something major?
private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}
This will output the following: "undefined checked: undefined"
Now in the function directly above it, I have the following function:
public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}
And this function will correctly output the checkbox name as well as update the position.
If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.
In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.
Any ideas? This is really annoying!
Thanks!!!
Edited: 06/27/2007 at 03:30:12 PM by JoMasta
[F8] Running Functions From Within Functions In A Class
For some reason, whenever I try to run a private function from within another private function in a class, it doesn't work.
Code:
private function getVars(theVar) {
switch (theVar) {
case "m" :
return this.m;
break;
case "nI" :
return this.nI;
break;
case "rX" :
return this.rX;
break;
case "rY" :
return this.rY;
break;
case "cX" :
return this.cX;
break;
case "cY" :
return this.cY;
break;
case "s" :
return this.s;
break;
case "a" :
return this.a;
break;
default :
return "";
}
}
Code:
private function cSpeed():Void {
// ccX is just a placeholder for the cX variable
// so that the function can use it.
var ccX:Number = cX;
m.onMouseMove = function() {
s = (this._xmouse-ccX)/1500;
getVars("m");
}
}
I just used getVars("m") for the hell of it...just to see if it would work...but it didn't. Any idea why not?
[F8] Calling Functions Within OnEvent Functions.
Ive just stumbled upon an annoying problem, Im writing a custom class which, in its constructor attaches a movie clip to a main one (passed in as a parameter).
this all works fine.
My problem arises when i try to, also in the constructor, create an onRollOver event on the movieclip i attached earlier (its stored in a field).
The onRollOver event works fine, calling the trace statement ive been using, but it won't call any function which i ask for.
this is the code where im having issues:
Code:
function Corner(xPosition:Number, yPosition:Number, circ:Circle, deep:Number, baseClip:MovieClip)
{
this.image = baseClip.attachMovie("Corner","CornerX",deep);
this.image._x = xPosition;
this.xPos = xPosition;
this.image._y = yPosition;
this.yPos = yPosition;
this.circle = circ;
this.image.onRollOver = function()
{
trace("debugOne"); //this trace statement works fine
this.otherFunction(); //Problem is here, The code wont call this function for some reason
}
this.depth = deep;
}
function otherFunction()
{
trace("debugTwo");
}
any ideas why its not calling my function?
[F8] Functions Inside Functions? Urgent
Hi, is this in any way valid?
Code:
this.onRelease = function(){
_root.mainbutton(){
freeze == false;
}
i have a set of buttons id like to play their animations when i press a button. Can this be done?
Any help or pointers would be greatly appreciated, thanks!
Declaring Functions In Other Functions And Callbacks
Hi - I'm curious to know if the following situation is possible (I haven't gotten it to work yet).
I'd like to load a series of images, and in the callback, place them in different positions in my array. Instead of writing a separate callback for each image, I'd like to do something like the following:
But it looks like each version of the function gets the end version of "i", not the version of i that existed when the function was declared.
Is something like this at all possible?
Attach Code
public function loadImages():void
{
for (var i:int = 0; i < 4; i++)
{
function myCallback(e:Event):void
{
myArray[i] = Bitmap(e.target.loader.content);
}
loadImageWithCallback(image, myCallback);
}
}
Functions Passed As Arguments To Other Functions
FLASH MX 2004 - AS2.0
I have a function with 4 necessary arguments (aka parameters) in order to perform the actions. I would like to have the ability to pass the same function to itself as an argument (sort of like a recursive function) along with its arguments. Basically I want to "base" to engage an onMotionFinished event handler if there is another function passed as an argument. Something like...
PHP Code:
function base (arg1, arg2, arg3 arg4, {arg5:another function, arg6:arg5s arg).....}){ //do the stuff instructions = blahblahblah if (arg5 is present){ instructions.onEventHandler = function(){ //perform function which is arg5...argN } } }
Would there be a way to use listeners to do this or the AsBroadcaster? Thanks
Functions Trough Functions...
Hi, I have some problems with relative/absolute functions...
The code is:
--------Main.fla:
Code:
import Bus;
var aBus:Bus=new Bus(wooz);
function wooz()
{
trace("wooz!!");
trace(this);
}
this.onMouseUp=function()
{
wooz();
}
wooz();
aBus.TryCallback();
---Bus.as
Code:
class Bus
{
var _couleur:String;
private var _Func:Function;
function Bus(Func:Function)
{
trace("exec func...");
_Func=Func;
}
function TryCallback()
{
_Func();
}
}
I would like to have an output like this:
wooz!!
_level0
wooz!!
_level0
...But i obtain this
wooz!!
_level0
wooz!!
[object Object]
I would like to keep _level0 as this, and not object, who aBus
Can U help me please???
thanks
Trace A Functions Name From Within Functions
I am setting up a series of function. I want to use the function name as a variable inside each function like this:
var thisFunction;
function functionName(){
thisFunction = this.name
trace(thisFunction)
}
I want to set funcName to the the name of the function, someName.
Thanks in advance!
Functions Inside Functions?
Hello all -
The following code is in a external AS file that is called in the first frame of the movie. When I have it play outside of a function, it works fine. As soon as I put inside a function, it does not work. The code is
ActionScript Code:
var _mcl:MovieClipLoader = new MovieClipLoader();
var _listener:Object = new Object();
_listener.onLoadInit = function(_mc:MovieClip)
{
trace("Done loading...");
}
_mcl.addListener(_listener);
this._mcl.removeMovieClip(clip_1);
this.createEmptyMovieClip("clip_1", this.getNextHighestDepth());
_mcl.loadClip("back.swf", clip_1);
I am new to AS, so I am trying to figure out if something in this code is not allowed when I put it into a function. I tested the function using trace statements to make sure it was being called and it was, so the problem seems to lie in this code. Does anybody know why this code will not work when put in a function? Thanks!
Functions Calling Other Functions
what i need to do is call a set of functions several times in sequence with different parameters each time. here's what i've got
Code:
/////photoload code////
this.fadeSpeed = 10;
this.fadeSpeed2 = 10;
var picToLoad = "";
var whereToLoad = "";
MovieClip.prototype.changePhoto = function(ddd,whatwhat) {
this.picToLoad = ddd;
this.whereToLoad = whatwhat;
trace("this.picToLoad = ddd **** "+this.picToLoad+" + "+ddd);
trace("this.whereToLoad = whatwhat ***** "+this.whereToLoad+" + "+whatwhat);
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.whereToLoad._alpha>this.fadeSpeed) {
this.whereToLoad._alpha -= this.fadeSpeed;
} else {
this.loadPhoto2();
}
};
MovieClip.prototype.fadeOut2 = function(xox) {
trace("fadeOut2 function called");
this.whichToFade = xox;
if (this.whichToFade._alpha>this.fadeSpeed2) {
this.whichToFade._alpha -= this.fadeSpeed2;
}
};
MovieClip.prototype.fadeOut3 = function() {
trace("this.whichToFade = "+this.whichToFade);
if (this.whichToFade._alpha>this.fadeSpeed) {
this.whichToFade._alpha -= this.fadeSpeed;
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.sectImg;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
//this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadPhoto2 = function() {
// specify the movieclip to load images into
var p = this.whereToLoad;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.picToLoad);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.whereToLoad.getBytesLoaded();
t = this.whereToLoad.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.whereToLoad._alpha<100-this.fadeSpeed) {
this.whereToLoad._alpha += this.fadeSpeed;
} else {
this.whereToLoad._alpha = 100;
this.onEnterFrame = null;
}
}
and then i've written the following to run the above functions:
Code:
MovieClip.prototype.controlPhoto = function(props) {
var ddd;
var whatwhat;
trace("arguments.length = " + arguments.length);
trace("props = "+props);
trace("arguments = "+arguments);
for (var cpi = 0; cpi<arguments.length; cpi++) {
trace("------ "+ cpi + " ------");
trace("arguments[cpi] = "+arguments[cpi]);
var my_array:Array = arguments[cpi];
my_array.slice();
trace(my_array[0]+" *** "+my_array[1]);
ddd=my_array[0];
whatwhat=my_array[1];
this.changePhoto(ddd,whatwhat);
}
}
and i'm calling this function like this:
Code:
curr_item.onRelease = function() {
_root.controlPhoto([this.img1,sectImg],[this.img2,leadImg]);
}
but what happens is only the last set of parameters actually get loaded. everything else seems to be skipped over. any help is appreciated!
thanks,
david
Mc Functions Inside Functions
I created an empty movie clip. The object in the clip is drawn with actionscript.
I wanted for the object to do different things when different keys were pressed. Like so:
ActionScript Code:
clip.onKeyDown = function() {if (Key.getCode() == Key.DOWN) {clip.onEnterFrame = function() {_root.callFunction();}} else if (Key.getCode() == Key.UP) {clip.onEnterFrame = function() {_root.callFunction();}}}
It's a simple example showing that the onEnterFrame function does about the same thing for each keys. Am i doing this right, or can the onEnterFrame function be defined once and i can call it from the onKeyDown function?
Thanks,
Jerome
|