Return Function Once LoadClip Is Complete.
Ok, I think this will prob. be simple for you AS experts out there, here's my code:
Code: function loadPic(whichPic):Void { var i:Number = 0; var pic:String;
var mcl:MovieClipLoader = new MovieClipLoader(); var mclL:Object = new Object(); mclL.onLoadProgress = function(target,loaded,total){ trace("loading:"+total+"bytes"); } mclL.onloadInit = function(){ trace("finished loading"); } mcl.addListener(mclL);
switch (whichPic) { case "steam": pic = "flash/flashImage-stream.jpg"; break; case "house2": pic = "flash/flashImage-house2.jpg"; break; case "house3": pic = "flash/flashImage-house3.jpg"; break; case "balcony": pic = "flash/flashImage-balconey.jpg"; break; }
mcl.loadClip(pic,mainImage); } What I want to do, is force the function to ONLY return once the file has finished loading. How can I do this??
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 05-25-2007, 03:04 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Return Function Once LoadClip Is Complete.
Ok, I think this will prob. be simple for you AS experts out there, here's my code:
[CODE]
function loadPic(whichPic):Void {
var i:Number = 0;
var pic:String;
var mcl:MovieClipLoader = new MovieClipLoader();
var mclL:Object = new Object();
mclL.onLoadProgress = function(target,loaded,total){
trace("loading:"+total+"bytes");
}
mclL.onloadInit = function(){
trace("finished loading");
}
mcl.addListener(mclL);
switch (whichPic)
{
case "steam":
pic = "flash/flashImage-stream.jpg";
break;
case "house2":
pic = "flash/flashImage-house2.jpg";
break;
case "house3":
pic = "flash/flashImage-house3.jpg";
break;
case "balcony":
pic = "flash/flashImage-balconey.jpg";
break;
}
mcl.loadClip(pic,mainImage);
}
[/CODE]
What I want to do, is force the function to ONLY return once the file has finished loading. How can I do this??
Wait Until Complete Some Function And Return Result
Hello,
I am new comer in as and flex, My problem is next
:during invoking some function I should get data from server side and
then return result
override flash_proxy function getProperty(name:*):* {
this.remoteObject.source = BOOK_SOURCE;
var callOperation:AbstractOperation =service.getOperation(LOAD_METHOD);
callOperation.addEventListener(ResultEvent.RESULT, resultMethodLoad);
callOperation.send();
return result;
}
private function resultMethodLoad(e:ResultEvent):* {
return (e.result as ArrayCollection);
}
how I can to stop current thread invoking while get information from server and return result of resultMethodLoad
without looping
Thanks
LoadClip Return Value Always TRUE
Greetings,
so here i am, trying to preload some content into my page and filter out possibility of error when fetching preloaded parts using loadClip method.
Code:
function loadContent(sLoadContent, nContentX, nContentY){
this.createEmptyMovieClip("mcHolder", 40);
var oListener:Object = new Object();
oListener.onLoadStart = function(){
preloader.preloadStart(mcHolder);
};
oListener.onLoadComplete = function(holder:MovieClip) {
// position preloaded content etc.
};
var mclLoader:MovieClipLoader = new MovieClipLoader();
var val = mclLoader.loadClip(sLoadContent, mcHolder);
if(!val){
loadContent("error.swf", 300, 280);
}
mclLoader.addListener(oListener);
}
Now the problem is with value returned by loadClip method. It should be false if there was error fetching content from HDD/server, but even if there is such error(and i get Output pannel message "Error opening URL "file:///C:/test.swf" " ), variable "val" is still TRUE (guess it should be FALSE).
Q: How can i filter such error when file is not available on server so that i can take appropriate action?
Thanks for helping out!
Return To Frame 1 On Timeline After Video Is Complete
Hello all,
My apologies beforehand if this is too noob, but I'm desperate. I have a simple, 2 frame FLA file with a button on the first frame going to frame 2 with a progressive download video, FLV Component, ready to play. The goal is after the video is complete I simply need the swf to return to frame 1 and its button. I see some solutions out there, especially for net streaming and such but I can't seem to pinpoint my specific problem. I'm having a real difficult time figuring out this task. Flash 8, AS2. Please, please, help...Thanks.
Return A Obj From A Class, After A URLLoader.addEventListener(Event.COMPLETE,onJSON);
Hey all,
coment below
ActionScript Code:
loadJSON.init("data.json");//run from Doc Class
function parentTrace(decoded)
{
trace(decoded);
}
loadJSON.as
ActionScript Code:
package
{
import com.adobe.serialization.json.*;
import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
public class loadJSON extends MovieClip
{
public static function init(jsonFile):void
{
var loader:URLLoader=new URLLoader;
loader.addEventListener(Event.COMPLETE,onJSON);
loader.load(new URLRequest(jsonFile));
}
public static function onJSON(e:Event):void
{
var jsonData:String=e.currentTarget.data;
jsonData=jsonData.replace(/
/g,"");
var decoded:Object=JSON.decode(jsonData);
stage.parentTrace(decoded); // this does not work
//i just want decoded to be push back to where the class was called after the file load.
}
}
}
AS2: What Datatype Should A Function Return, If It May Not Return *anything*?
The title of this post may not make much sense, let me explain...
I have a function:
findSurface(origin:Point, vector:Point, attempts:Number):Point {...}
The function has an obscure use, but the idea is thus: given those three arguments, returns a point IF the 'line' (created by the origin and vector arguments) intersects the object the function is called on. [but that is another story...]
More importantly, if there is no point of intersection at all, what should the function return? Void? Null? Undefined? Object? Or can I use one of those return types instead of Point incase the function does not encounter an intersection?
I'd be glad to try explaining better if anyone might know, thanks.
LoadClip Inside The Function()
hello, i´m trying to make a loadClip (by MovieClipLoader) inside a function, but it doesn´t work...and I don´t know why....
please can someone help me?
this is the code that i´m try to use
//to create the class:
var carregador:MovieClipLoader = new MovieClipLoader();
var ouvidor:Object = new Object();
carregador.addListener(ouvidor);
_root.createEmptyMovieClip("alvo",100);
alvo._x = 11
alvo._y = 78
link = "contato.swf"
/*if I put the loadClip action here, the movie clip loads correctly, but I need to use this action inside the function....*/
//to use the loadClip inside the function:
function clipLoader () {
count ++
this.onEnterFrame = function () {
fundoMask._yscale = fundoMask._xscale
fundo._yscale = fundo._xscale
if (fundo._xscale <= 0) {
aciona = true
}
if (aciona) {
fundo._xscale = 20 + (fundo._xscale - 20)/1.2
fundo._alpha = 50 + (fundo._alpha - 50)/1.2
if (fundo._xscale > 19.8) {
carregador.loadClip(link, alvo)
}
ouvidor.onLoadStart = function() {
avisos = "carregando..."
};
trace(_root.alvo.nome2.length)
ouvidor.onLoadInit = function() {
alvo.setMask(fundoMask)
};
ouvidor.onLoadComplete = function() {
//avisos = ""
fundo._alpha +=4
fundo._xscale = tamanho + (fundo._xscale - tamanho)/1.058
if (fundo._xscale > 89) {
fundoMask._xscale = 89 +(fundoMask._xscale - 89)/1.3
}
}
ouvidor.onLoadError = function() {
avisos = "ocorreu algum erro"
};
}
}
}
LoadClip Function Not Working
hi, i have some code that i am using to try and create a scrolling row of images..
Code:
photoArray = ["Pic01.jpg", "Pic02.jpg", "Pic03.jpg", "Pic05.jpg", "Pic06.jpg", "Pic07.jpg", "Pic08.jpg", "Pic09.jpg", "Pic10.jpg", "Pic11.jpg"];
imageHolder=content_mc.photogallery_mc.photoline_mc.createEmptyMovieClip("imageHolder_mc", 0);
imageHolder._width=522;
imageHolder._height=115;
content_mc.photogallery_mc.mask._alpha=50;
var nextX:Number;
for(i=0;i<photoArray.length;i++){
imagePath=imageHolder.createEmptyMovieClip("image_"+i+"_mc", i);
var imageMcLoader:MovieClipLoader = new MovieClipLoader();
var imageListener:Object = new Object();
imageMcLoader.addListener(imageListener);
imageListener.onLoadComplete = function(target_mc:MovieClip) {
//actions would go here
};
imageListener.onLoadInit = function(target_mc:MovieClip) {
//actions would go here
};
imageListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
//actions would go here
};
trace(imageListener.loadClip(_l1 + photoArray[i], imagePath));
}
now the idea is that for each image in the array, an empty MC is created and the image is loaded into it and becomes part of my of scrolling line of images..
the problem is that the loadClip() function does not get called. when i trace like in the above code it returns undefined.. can anyone pls give me some assistance.. ??? thanks in advance..
i should mention that this is the first time i am attempting to use this function and i edited the code from the macromedia help example..
Help With LoadClip Function(im Stumped)
SOLVED(but this might help for future referance)
Solutions:had to use myListener.onLoadInit to read when the entire movie was loaded
had to use duplicateClip instead of attachMovie because for some reason attachMovie could not find the movie clip i wanted to attach
Had to change my array to a Number() because when i added +1 instead of rewriting the new value as 2 it wrote it as 11
Working Script:
PHP Code:
function buildMap (myMap) { var mapWidth = myMap["base"][0].length; var mapHeight = myMap["base"].length; var myListener = new Object(); var myMovieClipLoader = new MovieClipLoader(); _root.attachMovie("empty","gameContainer",++curDepth); _root.gameContainer.attachMovie("empty","map",++curDepth); _root.gameContainer.map.attachMovie("empty","baseLayer",++curDepth); myListener.onLoadInit = function(target) { for (var i = 0; i<mapHeight; ++i) { for (var j = 0; j<mapWidth; ++j) { var newName = "t_"+i+"_"+j; _root.gameContainer.map.baseLayer.tiles.duplicateMovieClip("t_"+i+"_"+j, ++curDepth); _root.gameContainer.map.baseLayer["t_"+i+"_"+j]._x = (j*tileW); _root.gameContainer.map.baseLayer["t_"+i+"_"+j]._y = (i*tileH); _root.gameContainer.map.baseLayer["t_"+i+"_"+j].gotoAndStop(Number(myMap["base"][i][j][0])+1); } } } myMovieClipLoader.addListener(myListener); myMovieClipLoader.loadClip("Resources/rec001.swf","_root.gameContainer.map.baseLayer");}
Problem:
hey guys currently im making a flahs mmorpg and i want the game to run really smooth. My theory behind everythign is to carry and execute as little information inside flash as possible(to hopefully increase gameplay and smoothness of how the game runs). anyways to accomplish this i'm planning to load everything from external flash and php files and also to run Ajax and other javascript codes(for example for the player inventory which will be loaded on the HTML page insteado o f in flash). my problem is when im trying to load my mapResources(which contains all of the tiles for that map) im not able to call attach any movie clip that cmoes with it. here the funciton that im running:
PHP Code:
function buildMap (myMap) {var mapWidth = myMap["base"][0].length;var mapHeight = myMap["base"].length;var myListener = new Object();var myMovieClipLoader = new MovieClipLoader(); _root.attachMovie("empty","gameContainer",++curDepth);_root.attachMovie("empty","resourceData",++curDepth);_root.gameContainer.attachMovie("empty","map",++curDepth);_root.gameContainer.map.attachMovie("empty","baseLayer",++curDepth); myListener.onLoadInit = function(target) {for (var i = 0; i<mapHeight; ++i) {for (var j = 0; j<mapWidth; ++j) {var newName = "t_"+i+"_"+j;_root.gameContainer.map.baseLayer.attachMovie("_level0.resourceData.tiles", newName, ++curDepth); //I've attempt to load "tiles" here and that didnt work either_root.gameContainer.map.baseLayer[newName]._x = (j*tileW);_root.gameContainer.map.baseLayer[newName]._y = (i*tileH);_root.gameContainer.map.baseLayer[newName].gotoAndStop(myMap["base"][i][j][0]);} }} myMovieClipLoader.addListener(myListener);myMovieClipLoader.loadClip("Resources/rec001.swf","_root.resourceData");}
Alright so this function pretty much loads an Array(myMap) and first find the width and height fo the map. then afte doing so it loads a couple fo containers for the gamenot really relavent to the issue) after this it sets a listener object thats ays when my resource(the tiles for the game map file has loaded to run a function. in this function it reattachs a movieclip and then stops on a frame according to the Array(myMap) that we loaded. on each of the newly attach Movie clip's frame is a diffrent piece of map.. so when all is said and done the function should output a beautiful looking healthy map. but this is not so
anyways i ran this script in debug mode and everything work sfine when i use a movie clip that is in the same move as this , but once i try to call the movieclip from the loadClip funciton i have it doesn't work.
anybody have any ideas at how to fix this or any other solutions to my problem that might work better? Im thining abotu trying to use duplicateMovieClip or somehting, anyhelp would be really great!
LoadClip Inside The Function()
hello, i´m trying to make a loadClip (by MovieClipLoader) inside a function, but it doesn´t work...and I don´t know why....
please can someone help me?
this is the code that i´m try to use
//to create the class:
var carregador:MovieClipLoader = new MovieClipLoader();
var ouvidor:Object = new Object();
carregador.addListener(ouvidor);
_root.createEmptyMovieClip("alvo",100);
alvo._x = 11
alvo._y = 78
link = "contato.swf"
/*if I put the loadClip action here, the movie clip loads correctly, but I need to use this action inside the function....*/
//to use the loadClip inside the function:
function clipLoader () {
count ++
this.onEnterFrame = function () {
fundoMask._yscale = fundoMask._xscale
fundo._yscale = fundo._xscale
if (fundo._xscale <= 0) {
aciona = true
}
if (aciona) {
fundo._xscale = 20 + (fundo._xscale - 20)/1.2
fundo._alpha = 50 + (fundo._alpha - 50)/1.2
if (fundo._xscale > 19.8) {
carregador.loadClip(link, alvo)
}
ouvidor.onLoadStart = function() {
avisos = "carregando..."
};
trace(_root.alvo.nome2.length)
ouvidor.onLoadInit = function() {
alvo.setMask(fundoMask)
};
ouvidor.onLoadComplete = function() {
//avisos = ""
fundo._alpha +=4
fundo._xscale = tamanho + (fundo._xscale - tamanho)/1.058
if (fundo._xscale > 89) {
fundoMask._xscale = 89 +(fundoMask._xscale - 89)/1.3
}
}
ouvidor.onLoadError = function() {
avisos = "ocorreu algum erro"
};
}
}
}
Problems With Variables & MovieClipLoader.loadClip() Function.
Hello,
I'm making a XML photogallery. Im using a MovieClipLoader to load multiple images on the screen at the same time.
I've assigned variable path to hold image[p].childNodes which returns gallery/051102.jpg.
eg. path = image[p].childNodes;
trace(path); //returns gallery/051102.jpg
so when I load the image into the MovieClipLoader,
eg. mcLoader.loadClip(path, image);
no images show up.
if i subsitute path with,
eg. mcLoader.loadClip("gallery/051102.jpg", image);
image gallery/051102.jpg shows up!
Any help is appreciated. Thank you.
irok
LoadClip Letting Me Attach OnRollOver Function
var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("zelda.jpg", container);
_root.container.onRollOver = function(){
trace('ZELDA!');
}
/*Now this SHOULD trace back 'ZELDA!' when I click on the picture of Zelda... Right? It doesnt, what am I doing wrong? Please help.
Function Complete?
Hey, i have a motion function that takes one or two seconds to complete. I have two variables that i would like to switch over when i release an object, however, it is essential that the variables switch AFTER the motion function is completed:
Code:
motionTween = function (newX) {
var speed = 0.12;
if (newX==undefined) {
newX = this._x;
}
//easing motion
this.onEnterFrame = function() {
var dx = newX-this._x;
if (dx<=0.5) {
this._x = newX;
delete this.onEnterFrame;
} else {
this._x += dx*speed;
}
};
}
Code:
focus_floor = _root.floor_1
unfocus_floor = _root.floor_2
Code:
unfocus_floor.onRelease = function() {
motionTween.apply (this, [20])
}
AFTER the motionTween has completed on 'unfocus_floor' (_root.floor_2), i want focus_floor = _root.floor_2 & unfocus_floor = _root.floor_1. This will work both ways (as once _root.floor_1 is unfocus floor, the same .onRelease function will be applied to it).
How can i make flash detect when the function is complete from OUTSIDE the function?
Any ideas? Help needed ASAP! thanks
Trying To Fire A Function When Another Is Complete
Hi all,
I've got a function that moves my mc. What I'm trying to do is tell it to fire another function that will tell a movie clip to fade in over top once that destination is acheived. This will load a different mc for all my buttons. I'm not quite sure how to approach it. I've tried the if statement and it happens too quick. What should I be doing? Thanks in advance!
function moveIt() {
myMc.onEnterFrame = function() {
this._y += (_root.yPos-this._y)*.2;
this._x += (_root.xPos-this._x)*.2;
};
}
button.onPress = function() {
_root.xPos = -880;
_root.yPos = -1156;
_root.moveIt();
// run this additional function after my destination is reached
};
Thanks again!
Waiting Until A Function Is Complete
Hi guys,
Been trying to work out the best way to do this and thought someone might have some ideas. I am using AS2 in Flash 8.
I am calling a function I wrote which moves a mc across the screen. When the function is finished I want to move onto the next frame. In the main time line I have the following:
myFunction();
gotoAndPlay("nextFrame");
Here flash doesn't wait for the function is complete and just moves onto the next frame without moving the mc.
I don't want to put the gotoAndPlay inside the function as it needs to be reusable in different scenarios.
The best thing I have come up with is for myFunction to return "true" when it has completed and then on the main time line have:
myFunction();
this.onEnterFrame = function(){
if(flag == true){
gotoAndPlay("nextFrame");
}
Any of you got any other suggestions or is this the best way? I think there is a function in AS3 that does this, but obviously I don't have that.
Cheers for your help in advance
Function For 2 Events Complete?
for the code:
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
is it possible to have it so that a function doesnt execute until 2 things are loaded or is the best way a simple tree function where you have
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
function loadXml
{
nextLoad.addEventListener(Event.COMPLETE, LoadXML2);
}
just wondering is all, thanks
Dan
Checking When Function Is Complete?
Is there a way to add a listener or something to a function so when it's finished it will run another function?
I need to run a function in a class, and when it's completed run a function on the main timeline or elsewhere.
Thanks!
Complete Reset Function
Hey all.
I'm almost embarresed to ask this, but this is the newb forum and I'm a newb.
I have a project where I'm making an animation for a client, a projector basically.
There's non-scripted animation going on in the main timeline and the basic stop action at the end.
On the main timeline there are several movieclips with individual animations that needs to be in movieclips due to transitions going on on the main timeline.
the movieclips also contain stop actions at the end since the need to stop in a finished state.
Now I want a reset button that plays the projector from the start all over.
A simple gotoAndPlay doesn't work since that means that all movieclips on the main timeline is already animated and would stay on the stop frame.
I've read my books and searched the net but my lack of AS knowledge has prevented me from finding a solution. So I now crawl to the cross and beg you for help.
How should I write this action so that it goes to frame 1 of the main timeline and plays from there, but also resets all movieclips to their frame 1.
Grateful for help, regards / Johan
Return Function Name (Function => String)
I keep coming across problems where it would be really convenient to get the name of a function in string format - like arguments.callee only a string instead of [Function, Function].
I haven't thought of a way to do this but in my head the keywords 'prototype' and 'override function' keep coming up - albeit that seems like a horrible horrible idea, but Function does extend Object so...thoughts?
Return From Function Called Within Function
How do I return the output from getTrialsHandler to getTrials when calling getTrials?
// THE CALL
trace( getTrials(1,16) );
// THE FUNCTIONS
function getTrials(day, userID){
var pc:PendingCall = service.getTrials(day, userID);
pc.responder = new RelayResponder(this, "getTrialsHandler", null);
}
function getTrialsHandler(re:ResultEvent, day){
if(!re.result){
trace("ERR: load trials for day"+day);
} else {
trace("SUC: load trials for day"+day);
if(re.result[1] > _root.currentDay){
goto = "closed";
} else if(re.result[0] < 5){
goto = "open";
} else if(re.result[0] == 5) {
goto = "full";
}
out = (re.result[0]+"::"+re.result[1]);
}
return out;
}
Show Frame Before Function Is Complete?
Hello,
I have a two frame movie. On the first frame is a button with the code:
Code:
_parent.gotoAndStop(2);
On the second frame, I want to show iterations of a calculation as the calculation is running. Here's the code for frame 2:
Code:
stop();
calculate();
function calculate() {
for (var f = 1; f <= 30000; f++) {
resultsField.value = "Completed " + f + " of 30000 iterations.";
}
}
The problem I am having is that frame 2 doesn't show until the calculate() function is completed. So, instead of seeing the resultsField advance through the 30000 iterations, I just wait on frame 1 until the function has completed and then I see the final 30000th iteration on frame 2.
Is there a way to show the iterations on frame 2 as the iterations are taking place?
Attached is the .fla with the example.
Thanks for your help!
Initiate Another Action After Function Complete
Can someone help me with this all I want to do is initiate another action after my fade out is complete - how would I set up flash to detect that the fade has reached zero opacity - and advance to the next frame of my movie. It will probably involve some kind of if/else statement. Here is my code:
function fadeOut():Void {
my_mc.tintTo("#000000", 100, 5, "easeOutBounce");
}
fadeOut()
I call the function then I want to write something like:
if (fadeOut() == true) {
gotoAndPlay(3);
}
else
{
doNothing
}
Obviously how nice and simple if that worked but it doesn't - any suggestions warmly appreciated.
Regards
Chris
Mx Transitions - Writing Function To Fire When Complete?
Hi! I have the following function which moves my map on the stage using the built it mx transition tweens. It works great:
var easeType = mx.transitions.easing.Back.easeInOut;
function moveIt(x,y,xsc,ysc) {
myTweenX = new mx.transitions.Tween(_root.map, "_x", easeType, _root.map._x, x, 2, true);
myTweenY = new mx.transitions.Tween(_root.map, "_y", easeType, _root.map._y, y, 2, true);
myTweenXscale = new mx.transitions.Tween(_root.map, "_xscale", easeType, _root.map._xscale, xsc, 2, true);
myTweenYscale = new mx.transitions.Tween(_root.map, "_yscale", easeType, _root.map._yscale, ysc, 2, true);
}
I have the function called when a user presses a button, like this:
on (release) {
moveIt(800,-10,120,120);
}
Now I want to actually run to tweens when the user presses the button instead of just one (so the map always resets by going to one position first, and then runs the new cordinates once the first has completed). i don;t know where to start though, is there a on (complete) or something I can use with the moveIt(); function?
The following pseudo-code is the general idea, where the resetMap function is basically a duplicate of the moveIt function above. The code is completely incorrect I know, but I am just trying to get the general idea across... -
on (release) {
//run first function to zoom back out and reset map
resetMap(800,-10,120,120);
//once the first moveIt function above is done, then do the second (code all wrong of course!)
if resetMap(complete) {moveIt2(800,-10,120,120);}
}
Function Call On VideoEvent.COMPLETE Issue
Quote:
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
import flash.display.Loader;
import flash.display.MovieClip;
import fl.video.VideoPlayer;
import fl.video.VideoEvent;
//create pipe for data to transfer through
var videoConnection:NetConnection = new NetConnection();
videoConnection.connect(null);
//open pipe so data can pass through
var videoStream:NetStream = new NetStream(videoConnection);
//add video object from library to stage
addChild(vidPlayer);
//associate the video object with the open pipe
vidPlayer.attachNetStream(videoStream);
vidPlayer.addEventListener(fl.video.VideoEvent.COM PLETE, onFlvCompleteHandler);
function onFlvCompleteHandler(v:VideoEvent){
//add choice 3 to stage
var newChoice3:dec3_btn = new dec3_btn();
addChild(newChoice3)
//setting the X and Y position
newChoice3.x = 125
newChoice3.y = 150
//adding event listener of button click
newChoice3.addEventListener(MouseEvent.CLICK, removeChild3);
}
When I try to test the code I get an "1046: Type was not found or was not a compile-time constant: VideoEvent." error.
I just want to load up buttons when a FLV has completed finishing. Does anyone have any idea what is wrong? Thank you in advance.
Get The Object Being Loaded Within Event.Complete Function?
I am applying loader.contentLoaderInfo listeners to object in a loop. Is there a way to get the object that has called the Event.Complete and the associated function?
for example:
private function completeHandler(event:Event):void {
trace (the Loader object that called this function);
}
???
It seems like there would be something similar to 'event.target' but I understand that it is the contentLoader that has the eventListener applied to it. Thanks!
Edited: 11/27/2007 at 02:40:30 AM by masterkrang
Call Function Scripted On Tween Complete
im trying to make an event listener for a when a tween completes, and im not having any luck, any advise
my script
function startmove(event:KeyboardEvent) {
switch (event.keyCode) {
case 17 :
if ((blasts>0) && (blown)) {
blasts -= 1;
updateblasts();
blown = false;
blastx = ship.x;
blasty = ship.y-(ship.height/2);
bomb = bhold.addChild(new blast());
bomb.name = bomb;
bomb.x = blastx;
//bomb.addEventListener(Event.ENTER_FRAME, dropbomb);
bombtween:Tween = new Tween(bomb, "y", null, blasty, blasty-200, .5, true);
}
break;
}
}
bombtween.addEventListener(Event.COMPLETE, removebomb);
how can i make it call the removebomb function after the tween is completed???
AddEventListener(Event.COMPLETE, OnLoaded) Function Problem
hi, everyone, i am new and i need help
i hope my problem is not one everyone knows and talks about, but i couldn't really find an answear to it via google, and am a little bit desperate to find a solution..
problem is: the
addEventListener(Event.COMPLETE, onLoaded) does not finish what it should do before i call the
addEventListener(Event.ENTER_FRAME, loop) function, or so it seems..
WHY!?!?
i do not really understand why this is happening, maybe someone can explain to me where my thinking is wrong..
the error msg is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
that shouldn't be possible tho, since i initialize the concerning variable (sc:Soundchannel) beforehand..
code:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class testprojekt extends Sprite
{
public var loader:URLLoader = new URLLoader();
public var sound: Sound = new Sound();
public var sc:SoundChannel = null;
public var xml:XML;
public var il: XMLList = new XMLList();
public var soundIndex:Number = 0;
public var soundEndIndex:Number;
public var speed:Number = 100;
public var chordList:XMLList;
public var testString:String;
public function testprojekt()
{
loader.load(new URLRequest("sound.xml"));
loader.addEventListener(Event.COMPLETE, onLoaded);
// chordList from SoundInput class
var sInput: SoundInput = new SoundInput("soundFile_test.xml");
chordList = sInput.getSoundInput();
addEventListener(Event.ENTER_FRAME, loop);
}
public function onLoaded(e:Event):void
{
// xml loaded
xml = new XML(loader.data);
il = xml.tracks.sound;
soundEndIndex = il.name.length();
// start first sound
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
sc = sound.play();
}
public function loop(e:Event):void
{
//trace("here is the error and i do not know why");
if (sc.position >= speed)
{
sc.stop();
setSound();
}
}
public function setSound():void
{
soundIndex++;
if (soundIndex < soundEndIndex)
{
trace(soundIndex);
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
trace(il.name[soundIndex]);
sc = sound.play();
}
else
{
removeEventListener(Event.ENTER_FRAME, loop);
}
}
}
}
thx for anyone reading this through
Return Function
Can somebody tell me how can I use return function for my film:
I have a large movie with 20 scenes and in every scene I have a webservice from where can user going to sitemap. But if user choos nothing, can he click return button, and appear again in the same scene and in the same position(I mean keyframe) from where he went.
If someone know return function, please tell me....
Function =>return Value ?
hey,
I wonder if anyone has any ideas how to do this :
I have a function written
Code:
javascript.openConfirm = function(message_str){
responsSet_bol ="false";
getURL("javascript:var respons = confirm('" + message_str + "');void(0);javascript:window.document.popup.SetVariable('respons_str',respons);javascript:window.document.popup.SetVariable('responsSet_bol','true');");
return respons_str;
}
what i want to accomplish is a confirm window(ok, cancel) and I want the answer to be returned
I call this like so:
Code:
respons = javascript.openConfirm("wilt ge dit?");
the problem is that the string is returned, before an answer is set by the confirm window.
does anyone have any ideas how to do this?
Return Value From Function
Hi,
this should be easy:
I have a little text function that works fine when I have it on frame one of a root MC that loads other MCs at runtime.
ActionScript Code:
function xvStrng(sText:String) :String {
var revText = "";
// code modifying sText
return revText;
}
I also have classes included in the root MC. The classes' functions work fine from all MCs, but non of them has to return anything.
When I put the "xvStrng" function into a class and call:
ActionScript Code:
someVariable = className.xvStrng("someString");
all I receive in "undefined".
Any ideas?
Thanks
David
How To Return In This Function?
Hi guys, hope you can help me on this one.
I have a class to load an XML file. I’m trying this:
Code:
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class retornaXML{
private var _xml:XML;
public function retornaXML() {
cargarXML();
}
private function cargarXML():void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(new URLRequest("LocalData.xml"));
}
private function xmlLoaded(e:Event):void {
_xml = new XML(e.target.data);
trace(_xml);
//THE TRACE HERE WORKS PERFECT AND RETURNS THE XML
}
public function get elXML():XML {
return _xml;
//THIS RETURNS null
}
}
}
I want something like this:
var mivariable:retornaXML = new retornaXML();
trace(mivariable.elXML);
but this trace returns null, since the xml file (I think) is not loaded yet. What should I do?
Thanks in advance.
HELP-Why Won't This Function Return A Value
I want to get this XML data OUT of the function, but it just won't work. What I am doing wrong??? Tracing "xmlList" gives me the output i want IN the function, but if I can't get it OUT. If i set the function to "String", I still can't get the function to return a value or anyway to get this data OUT of the function. Please help.
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader;
xmlLoader.load(new URLRequest("data/imagesT.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):String
{
xml = XML(event.target.data);
xmlList = xml.children()[0].child(2);
}
How To Return A Value From A Function, Maybe
Hello, first post :)
Here is my problem: In the attached .fla, I have a wheel of fortune style game which stops at a random point.
I've been able to test where the wheel stops using hitTest, and would like to output the result to the trace (for now).
My if statement which does the hitTest(s) is nested inside the function which slows and stops the wheel spinning (slowdown).
The problem is that function uses onEnterFrame, so my trace messages go into an endless loop.
So my question is how to test that the wheel has stopped spinning from outside the function, where to put the hitTests? My guess is it could involve getting the function to return a value, but I'm not sure.
Thanks in advance.
AS3 - Return Value From A Function.
Hey i am having a problem getting a value out of a function. It has been driving me crazy tried many ways of doing this... found a way to accomplish it in the .FLA file and it worked fine. But when i am working in .AS it just doesnt seem to work. Please help!
PHP Code:
public function parseUsers(usrInput:XML)
{
var userType:String = usrInput.Users.userType.toString();
trace("Username: " + usrInput.Users.userName + " User type: " + usrInput.Users.userType);
return userType;
}
The xml loads find parses fine everyting works inside the function... now how do i get those values out??? and how would i use them in a .swf ? Thanks in advance!
Function And Return
Hello,
I'm pretty newbie to actionscript 2, so my question might sound easy.
I can't understand the use of 'return' in a function.
If I write
ActionScript Code:
function some(num:Number) {
number = num * num;
}
some(8);
trace(number);
well, it works.
I could also have written
ActionScript Code:
function some(num:Number) {
var number = num * num;
return number;
}
some(8);
trace(number);
It works also, but I'm wondering why not using the first case?
Is 'return' used only where variable names might conflict with the rest of the code?
And, if I use methods within the code, the results of which are global, why should I use the return keyword, which is to resolve the 'locality' of functions?
thank you very much
m.
Function Return
hey,
I'm trying to make a function in flash to call a confirm dialog box through javascript. I wrote this function to open the confirmdialogbox and then storing the value in a variable respons and then sending this variable to the swf. At the end I return the value.
Code:
javascript.openConfirm = function(message_str){
responsSet_bol ="false";
getURL("javascript:var respons = confirm('" + message_str + "');void(0);javascript:window.document.popup.SetVariable('respons_str',respons);javascript:window.document.popup.SetVariable('responsSet_bol','true');");
return respons_str;
}
Now if I call this function doing this :
Code:
respons = javascript.openConfirm("ben je zeker dat je dit wil?");
the returned value isn't stored in the respons variable.
The reason I think is because the value is returned before you click one of the 2 buttons(ok or cancel).
does anyone have any idea how to avoid this. or an other method so the return value is the same as the button clicked
I really need some help, cause I'm stuck
[Type Function] Return? Wtf Is This?
I have script that creates an array of numbers, randomly choses one from that list, assigns this number to one of the MC's depth, removes it from the array, then moves on to next MC. The purpose is to randomly generate Depth levels.
v_?? are variables
a_?? array
c_?? Clips (MC's)
i_?? interger counters
f_?? functions
when I "trace" the result for the FishA, it displays [Type Function], OR reports the depth is -16383 (or some ridiculous #)
what have i done wrong? What does [Type Function] mean?
onClipEvent(load){
v_Depth = 0;
a_Depth = new Array();
for(i_Count = 0; i_Count < 30; i_Count ++) {
a_Depth [i_Count] = i_Count;
}
function f_SetupDepth(fv_MC) {
v_Depth = random(a_Depth.length);
trace(v_Depth);
_root[fv_MC].swapDepths(Number(v_Depth));
a_Depth.splice(v_Depth,1);
}
f_SetupDepth(c_Column1);
f_SetupDepth(c_Column2);
f_SetupDepth(c_Column3);
f_SetupDepth(c_Column4);
f_SetupDepth(c_Column5);
f_SetupDepth(c_Column6);
f_SetupDepth(c_FishA);
}
HELP Need A Function To Return 2 Values
ok, i've written a function and im trying to get it to return 2 different values
example of what i need
Code:
thisArray = myFunction(args)
----output----
thisArray[0] = first value
thisArray[1] = second value
is there a way to do this?
or do i return 1 string value which is a concantenated string of 2 values with an identifier in between?
Code:
thisVariable = myFunction(args)
thisArray = split(thisVariable, ":")
----output----
thisArray[0] = first value
thisArray[1] = second value
where the : is the identifier
im trying the second method now, but for some reason it returns 'undefined' all the time...
Return As Function Parameter
how to return true/false (or anything at all), when the parameter is a function?
code:
function f(g, arg) {
g.call(this, arg);
}
//simple working example
function move(mc) {
mc.onEnterFrame = function() {
this._x += 5;
};
}
f(move, ball);
//not working
function returnV(v) {
return v;
}
trace(f(returnV, true));//outputs undefined
function returnV2() {
return true;
}
trace(f(returnV2));//outputs undefined
Return Array From Function?
hi,
i have a function that takes an xml file as an arguments, reads the data and puts it into an array.
how do i get that array returned outside of the function?
i've tried " return array; " to no avail.
code:
function loadList(filename) {
audiolist = new XML();
audiolist.ignoreWhite = true;
audiolist.load(filename);
trackArray = new array();
audiolist.onLoad = function(success) {
loaded = true;
totalNodes = audiolist.firstChild.childNodes.length;
for (a=0; a<totalNodes; a++) {
thisCD = audiolist.childNodes[a]
tracklist = thisCD.childNodes.length;
for (i=0; i<tracklist; i++) {
trackArray.push(thisCD.childNodes[i].childNodes[0].nodeValue + ":" + thisCD.childNodes[i].attributes["id"]);
}
}
return trackArray();
}
}
onEnterFrame = function() {
if (!loaded) {
myArray = loadTrackList("tracklist.xml","")
for (i=0;i<myArray.length;i++) {
trace(myArray[i]);
}
}
What Does The CreateTextField() Function Return?
Hey everyone,
I've tried tracing a number of createTextFeild() functions and keep recieving 'undefined.' I suspect my problem is that the function doesn't actually return anything. Can anyone confirm this?
Thanks,
Greenham.
Return XMLNode From Function
Why is it that the trace from within the readXML function traces the XMLNode as expected, but the trace from within the onLoad returns undefined?
Shouldn't they trace out the same thing. Why doesn't the readXML function return the XMLNode?
ActionScript Code:
var myXML:XML = new XML();
var itemsNode:XMLNode;
var imageNode:XMLNode;
submitBut.onRelease = function() {
myXML.load("thisXML.xml");
}
myXML.onLoad = function(success) {
if (success) {
trace("From Load: " + readXML(myXML, "Items");
myText.text = readXML(myXML, "Items");
} else {
myText.text = "There was an error loading.";
}
}
function readXML(startNode:XMLNode, targetNode:String):XMLNode{
if (startNode.hasChildNodes) {
for (var i = 0; i < startNode.childNodes.length; i++) {
if (targetNode == startNode.childNodes[i].nodeName) {
trace("From read: "+startNode.childNodes[i]);
return startNode.childNodes[i];
}
readXML(startNode.childNodes[i], targetNode);
}
}
}
Thanks.
_t
Return Loaded XML From Function?
Hey everyone
I'm trying to figure out how to do this. I'm making an XMLLoader class, that I want to be able to use like this:
Code:
var myXML:XML = XMLLoader.load("SELECT * FROM table");
trace(myXML); // traces the loaded XML
I just can't figure out how to make the load function inside XMLLoader return the XML object... I can easily register an evenlistener that calls another function when the XML is loaded.. but how do I then make the load function return this XML? I want to do this:
Code:
package
{
public class XMLLoader
{
public function XMLLoader()
{
trace("Constructor called");
}
public function load(sql:String)
{
// Call a php site to recieve XML
// add listener to notice when XML is loaded
// return the loaded XML
}
}
}
The thing is, that I want to keep all event-stuff inside my XMLLoader, so I can use the class like the first example.
One way around it is to make a while loop inside the load function that checks whether a boolean is tru or false. When the XML is loaded, I set that boolean to true and the laod function returns the XML. But it's really taking up all the CPU power, and NOT a nice solution..
In a bunch of other programming languages you have the sleep function, that let's you sleep e.g. a part of a functions code until a variable is set, and then you can return it only when it is set.
How do I do it?
How To Return The XML Data From Function.
hi,
I am new to ActionScript. i need help from you. how to return and get the xml Data from function. this is my coding.
package {
import flash.events.*;
import flash.net.*;
import fl.data.DataProvider;
public class LoadXml
{
static var xmlData:XML =new XML();
public function LoadXmlFn():XML
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("DomainDetail.xml"));
xmlData=xmlLoader.addEventListener(Event.COMPLETE, LoadedXML);
return xmlData;
}
public function LoadedXML(e:Event):XML
{
xmlData = new XML(e.target.data);
return xmlData;
}
}
}
Please help me..
Advance thanks.
Different Return Values For A Function?
Hey,
I have a function which could return different types of possible datatypes,
depending on the input. What should i set to be the return value of the function in the definition?
Isn't this ok:
ActionScript Code:
public function getSubData(inDataType:string):Object {
var obj_to_return:object;
if (inDataType == "arr") {
obj_to_return = global_array; //An array with some sprites in it.
}
else if (inDataType == "sprite") {
obj_to_return = global_array[0]; //A sprite
}
return obj_to_return;
}
When using the function in my code:
var sprite_obj:sprite = getSubData("sprite");
i get:
"1118: Implicit coercion of a value with static type Object to a possibly unrelated type..."
Is this possible?
Thanks,
Guy
Return Function W/ SetInterval
I want to have a function that returns a value...this function will be called by setInterval.
The problem is...the function will return a value. I want to make sure that value goes to the proper variable. How can this be done?
Code:
EX:
function test(someInput){
return (someInput = 'dork');
}
interval_ID = setInterval(test, 10000, someInput);
// let's say i have a variable call "show"
// show should contain the return variable
Now, I tested out to see if I can pass a variable by address or reference to avoid 'return'...but it doesn't work. However, arrays can be used b/c it can be passed by referenced.
For example:
function test (theArray){
theArray[0]='dork';
}
var myArray = new Array();
myArray[0] = 'not a dork';
zeroArray(myArray);
trace (myArray[0]);
If you know how I can accomplish the same concept w/out using arrays, let me know.
thx in advance
Use Return Key To Trigger Function?
I've got a little form in a movieclip where the student is to do some simple subtraction, then click the Record button to enter the data into a table. Problem is that if someone types in the answer, they naturally want to hit the Return key to enter the data, however, it instead puts a carriage return in their answer and when they try submitting with the Record button, it checks their answer and it is now wrong since the added carriage return does not match the answer they should have. Is there any way to make the Return key trigger the recordIt() function? Here is my code:
Attach Code
recordBtn.addEventListener(MouseEvent.MOUSE_DOWN,recordIt);
function recordIt(num) {
if (diameter.text == "85.80") {
if (difference.text == "1.10") {
MovieClip(this.parent).growth.d1999.text = "85.80";
MovieClip(this.parent).growth.g1999.text = "1.10";
helpText.text = "Good job. Click the button below to do the next year's measurement.";
recordBtn.visible = false;
} else {
helpText.text = "Incorrect result. Try again.";
}
} else {
helpText.text = "Incorrect diameter. Try again.";
}
}
Return To A Calling Function
I need some help here, please.
I have several buttons calling the bounceOut() function and the bounceOut() function calls the onMotionFinish() function. After that function is finished I want to go back to the original calling function. Can someone help me with this?
First a call is made to bounceOut() when a button is clicked. I have ten buttons.
function bounceOut() {
var smSlide:Tween=new Tween(sideMenu_mc,"x",Regular.easeOut,200,-200,2,true);
smSlide.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinish);
}
function onMotionFinish(event:Event):void {
removeChild(pageTitle);
removeChild(sideMenu_mc);
removeChild(missionContent_mc);
removeChild(missionTitle_mc);
}
|