1120: Access of undefined property - actionscript-3

I am getting this error message when I try to access a button movieclip from inside a videoPlayer movieclip. They are not nested. When the videoPlayer button is clicked the buttons tween to the bottom of the screen out of the way whilst the videoPlayer sits in their previous location. On closing the videoPlayer I would like the buttons to tween back in from the right of the screen but I get the following error message "1120: Access of undefined property TweenMax.from(btn1, 3, {x:450, y:209.1, ease:Back.easeOut});. My question is what would I use in as3 to access control of the buttons so I can tween them on closing the videoPlayer movieclip. Any pointers would be greatly appreciated.
The flvPlayer script:-
stop();
closeBtn.addEventListener(MouseEvent.CLICK, closeVid)
closeBtn.buttonMode = true;
function closeVid(e:MouseEvent):void
{
video.stop();
gotoAndStop(1);
TweenMax.from(btn1, 3, {x:450, y:209.1, ease:Back.easeOut});
}
**********************************************************************
The script from outside the videoPlayer or scene1:-
import com.greensock.*;
import com.greensock.easing.*;
var numberOfButtons:Number = 3
var startX:Number;
var startY:Number;
var currentButton:MovieClip
for (var i:int = 1; i <= numberOfButtons; i++)
{
this["btn"+i].buttonMode = true;
this["btn"+i].mouseChildren = false;
this["btn"+i].addEventListener(MouseEvent.MOUSE_OVER, doRollover)
this["btn"+i].addEventListener(MouseEvent.MOUSE_OUT, doRollout)
this["btn"+i].addEventListener(MouseEvent.CLICK, showbtnContent);
}
function doRollover(e:MouseEvent):void
{
TweenMax.to(this[e.target.name], 1, {scaleX:1.1, scaleY:1.1, ease:Elastic.easeOut});
}
// This function handles the Rollout event
function doRollout(e:MouseEvent):void
{
TweenMax.to(this[e.target.name], 1, {scaleX:1, scaleY:1, ease:Elastic.easeOut});
}
function showbtnContent(e:MouseEvent):void
{
currentButton = this[e.target.name]
switch (currentButton)
{
case btn1:
TweenMax.from(audioPlayer, 1, {x:449, y:-112, ease:Back.easeOut});
audioPlayer.gotoAndStop(2);
audioPlayer.parent.setChildIndex(audioPlayer, audioPlayer.parent.numChildren-1);
break;
case btn2:
TweenMax.from(mcGallery, 1, {x:450, y:300, scaleX:1, scaleY:1, ease:Back.easeOut});
mcGallery.gotoAndStop(2);
mcGallery.parent.setChildIndex(mcGallery, mcGallery.parent.numChildren-1);
break;
case btn3:
TweenMax.to(btn1, 20, {x:450, y:777.1, ease:Elastic.easeOut});
TweenMax.to(btn2, 16, {x:450, y:777.1, ease:Elastic.easeOut});
TweenMax.to(btn3, 12, {x:450, y:777.1, ease:Elastic.easeOut});
TweenMax.from(flvPlayer, 3, {x:1060, y:280, ease:Back.easeOut});
flvPlayer.gotoAndStop(2);
flvPlayer.parent.setChildIndex(flvPlayer, flvPlayer.parent.numChildren-1);
break;
}
}

when you use gotoAndStop(1); it moves to the first frame, where the btn1,btn2 and btn3 did not exist.
fixing it will be tough, because you'll need to move the timeline into a separate MovieClip from the MovieClip or Sprite that is holding the buttons, so that this does not happen.

Related

AS3: How do I call a function with two arguments - (vBox, and vFile)

Adobe Flash CC
Sort of confused here. I'm working on optimizing my code so that instead of calling launchVideo(); for every single video I can can simply call it once, while passing a new source string to the function.
How do I call the launchVideo function from within another function?
When I add an event listener, which calls the playMPMovie
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, playMPMovie, false, 0, true);
function playMPMovieOne(): void {
video_file = "/videos/MP_01.mp4";
launchVideo();
}
I get this...
Scene 1, Layer 'actions', Frame 1, Line 21, Column 2 1136: Incorrect number of arguments. Expected 2.
When I try adding (vBox, vFile) to launchVideo(); I get this...
Scene 1, Layer 'actions', Frame 1, Line 20, Column 20 1120: Access of undefined property vFile.
Scene 1, Layer 'actions', Frame 1, Line 20, Column 14 1120: Access of undefined property vBox.
Here is the full code.
stop();
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Graphics;
import fl.video.*;
vinetteMC.visible = false;
// VARIABLES //
var video_holder: MovieClip = new MovieClip();
var video_file: String;
// EVENT LISTENERS //
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, playMPMovie, false, 0, true);
function playMPMovieOne(): void {
video_file = "/videos/MP_01.mp4";
launchVideo();
}
// Place Playback
function launchVideo(vBox, vFile): void {
var flvPlayer: FLVPlayback = new FLVPlayback();
import fl.video.*;
import flash.events.*;
flvPlayer.source = vFile;
flvPlayer.skinAutoHide = true;
flvPlayer.skinBackgroundColor = 0x000000;
flvPlayer.width = 1920;
flvPlayer.height = 1080;
flvPlayer.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
function completeHandler(event: Event): void {
removeChild(video_holder);
removeChild(flvPlayer);
flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler, false, 0, true);
trace("Complete handler called");
}
vBox.addChild(flvPlayer);
}
launchVideo(video_holder, video_file);
It looks like you are wanting to call
function playMPMovieOne(): void {
video_file = "/videos/MP_01.mp4";
launchVideo(video_holder, video_file)
}
Also from your example code the video holder is created but never added to the display list. You may need to add this to see anything.
addChild(video_holder);

How to correctly load und unload swf galleries for PORTFOLIO web site?

My problem looks like: I have five buttons and four of them are loading four different swf galleries into the main swf, the last one unloads all galleries. Each of them has exactly the same code, the only differeces are the locations of jpg files and swf files. Also each o them has the listeners ADDTOSTAGE and REMOVEFROMSTAGE, because i'm using the stage inside the gallery/swfs.
So when I enter the menu and load the first swf i don't get any output errors, when I click the btn_back he unloads the swf properly with no errors. And so on but only when i load only one gallery.
But when I, after loading the first gallery, want to click on another button and load second gallery then i got this error in output, so many times as many pictures are loaded inside the loaded swf/gallery:
TypeError: Error #1009: Nie można uzyskać dostępu do właściwości lub metody dla odniesienia do obiektu null.
at DocObject/resizeMyDoc()
at DocObject/onResizeDoc()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.display::Stage/dispatchEvent()
at Miniaturka/onAddedToStage()
at flash.display::DisplayObjectContainer/addChild()
at Miniaturki/callback()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at Miniaturka/onLoadComplete()
So my conclusion is that the problem is not inside the loaded swf but in the code of loading and unloading code of the mine swf. The only solution that I can find is: that when I click the second button the code should first unload the current swf, and when the unload is complete then immidietly load the another one. But I don't know how to write it. Can anyone help? So here is the code.
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.Loader;
var _mainLoader:Loader;
var _currentContent:DisplayObject;
var url:URLRequest;
var loaded:Boolean = false;
var a:Array = new Array(s1_1_arch, s1_2_arch, s1_3_arch, s1_4_arch);
var swfList:Array = ["A0101.swf", "A0102.swf", "A0103.swf"];
//Initiate Loader, do it only once
function initiateLoader():void {
_mainLoader = new Loader();
_mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
}
function loadGallery(path:String):void {
//Check if content previously loaded, unload it
if (_currentContent != null) {
removeChild(_currentContent);
_currentContent = null;
_mainLoader.unloadAndStop();
}
//Now load another one
_mainLoader.load(new URLRequest[1]);
}
function onComplete(e:Event):void {
_currentContent = _mainLoader.content;
//Add root DisplayObject of the loaded content to the display list
stage.addChild(_currentContent);
}
function samClick(e:MouseEvent):void
{
switch (e.target)
{
case s1_1_arch :
break;
case s1_2_arch :
break;
case s1_3_arch :
break;
case s1_4_arch :
break;
}
}
function samOver(e:MouseEvent):void{
switch (e.target)
{
case s1_1_arch : var sam1Ou:Tween = new Tween(s1_1_arch, "alpha", Strong.easeOut, 1, 0.2, 0.5, true);
break;
case s1_2_arch : var sam2Ou:Tween = new Tween(s1_2_arch, "alpha", Strong.easeOut, 1, 0.2, 0.5, true);
break;
case s1_3_arch : var sam3Ou:Tween = new Tween(s1_3_arch, "alpha", Strong.easeOut, 1, 0.2, 0.5, true);
break;
case s1_4_arch : var sam4Ou:Tween = new Tween(s1_4_arch, "alpha", Strong.easeOut, 1, 0.2, 0.5, true);
break;
}
}
function samOut(e:MouseEvent):void{
switch (e.target)
{
case s1_1_arch : var sam1Ou:Tween = new Tween(s1_1_arch, "alpha", Strong.easeOut, 0.2, 1, 0.5, true);
break;
case s1_2_arch : var sam2Ou:Tween = new Tween(s1_2_arch, "alpha", Strong.easeOut, 0.2, 1, 0.5, true);
break;
case s1_3_arch : var sam3Ou:Tween = new Tween(s1_3_arch, "alpha", Strong.easeOut, 0.2, 1, 0.5, true);
break;
case s1_4_arch : var sam4Ou:Tween = new Tween(s1_4_arch, "alpha", Strong.easeOut, 0.2, 1, 0.5, true);
break;
}
}
for (var i:Number = 0; i < 4; i++)
{
a[i].addEventListener(MouseEvent.CLICK, samClick);
a[i].addEventListener(MouseEvent.MOUSE_OVER, samOver);
a[i].addEventListener(MouseEvent.MOUSE_OUT, samOut);
}
Just to add...
For something like this you are better of having all code in one place. A class file will save you other frustrations later on if you're still new. Just control all elements from one place. Also consider what Nicolas Siver said in his answer..
Just a quick guide on how to setup class file. If you save as Main.as and attach to your FLA then you can paste in your timeline code here.
package
{
//IMPORTS go here
//Declare your Class (name of .as file)
public class Main extends MovieClip
{
//VARS go here
//Declare main function of your Class (must have same name as Class (.as file)
public function Main()
{
// Your main program code go here
//Something(); //example: run a function called Something
}
public function Something();
{
// Do something code
}
} //End of Class
} //End of Package
You are on the right way. But you have many problems in your code, most of your switches are redundant. By default, all galleries, that you are loading, will be loaded in child ApplicationDomains, so they are suitable for garbage collection.
If you will use single Loader it will be easier for you to manage it, and load one section in time.
//Pseudo code
Create main loader (with onComplete event handler);
Create a function for loading content, and call it.
Check if previous load operation was successful (use your flag `loaded`), if Yes - unload previous content, remove previous content from the display list;
Load new content;
After loading is completed, add content to the main display list holder, designed to show gallery content.
Also I would recommend to use TweenLite, It's also more developer friendly.
Here for you several utility functions that will help you accomplish your task:
private var _mainLoader:Loader;
private var _currentContent:DisplayObject;
//Initiate Loader, do it only once
private function initiateLoader():void {
_mainLoader = new Loader();
_mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
}
private function loadGallery(path:String):void {
//Check if content previously loaded, unload it
if (_currentContent != null) {
removeChild(_currentContent);
_currentContent = null;
_mainLoader.unloadAndStop();
}
//Now load another one
_mainLoader.load(new URLRequest(path));
}
private function onComplete(e:Event):void {
_currentContent = _mainLoader.content;
//Add root DisplayObject of the loaded content to the display list
addChild(_currentContent);
}
More concrete realisation, you could use it in your frame, but don't forget to do all imports, and create all necessary display object on the scene:
//Self explanatory
var currentContent:DisplayObject;
//Initiate Loader
var mainLoader:Loader = new Loader();
mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
//Create some MovieClip and give it a name, you will place loaded content there, ex: contentHolder
//Add buttons in one container (MovieClip) and give it name, ex: buttonHolder
//Give buttons some names, ex: s1Arch, s2Arch, s3Arch
//Map our buttons to external links and prepare for mouse events
var links:Object = {"s1Arch": "A0101.swf", "s2Arch": "A0102.swf", "s3Arch": "A0103.swf"};
//Register listeners, you could do it in cycle
s1Arch.addEventListener(MouseEvent.CLICK, onClickButton);
s2Arch.addEventListener(MouseEvent.CLICK, onClickButton);
s3Arch.addEventListener(MouseEvent.CLICK, onClickButton);
//Mouse events, using events bubbling
buttonHolder.addEventListener(MouseEvent.CLICK, onClickButton);
function loadGallery(path:String):void {
//Check if content previously loaded, unload it
if (currentContent != null) {
contentHolder.removeChild(currentContent);
currentContent = null;
mainLoader.unloadAndStop();
}
//Now load another one
mainLoader.load(new URLRequest(path));
}
function onClickButton(e:MouseEvent):void {
//Explanation step-by-step
//Clicked button
var button: DisplayObject = DisplayObject(e.currentTarget);
//Path to the external file
var path: String = links[button.name];
//Utility function will handle another stuff
loadGallery(path);
}
function onComplete(e:Event):void {
currentContent = mainLoader.content;
//Add root DisplayObject of the loaded content to the display list
contentHolder.addChild(currentContent);
}

Why does TweenLite.to and hitTestObject not work?

this is my code:
stop();
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.TweenMax;
import com.greensock.TweenLite;
import flash.events.Event;
import com.greensock.TweenLite
stage.addEventListener(MouseEvent.CLICK, rijden); // Add the button click
function rijden(e:MouseEvent):void {
TweenLite.to(auto, 4, {x:666.15, y:375.6});
}
addEventListener(Event.ENTER_FRAME, einde1);
function einde1(e:Event){
if(auto.hitTestObject(stopauto)){
var myTween=TweenLite.to(auto, 4, {x:666.15, y:375.6});
myTween.kill(); //here code for tween killing
trace("works")
//
auto.x = 241;
auto.y = 375;
removeEventListener(Event.ENTER_FRAME, einde1)
}
}
and I want that if auto hits stopauto, auto goes to
auto.x = 241;
auto.y = 375;
it does the trace but it doesn't go to the x and y what I want it to go
You have two tweens, one of them is never killed. I guess it simple goes on and overrides your x/y for the final car destination.
//tween one
function rijden(e:MouseEvent):void {
TweenLite.to(auto, 4, {x:666.15, y:375.6});
}
//tween two
function einde1(e:Event){
if(auto.hitTestObject(stopauto)){
var myTween=TweenLite.to(auto, 4, {x:666.15, y:375.6});
myTween.kill(); //here code for tween killing
//REST OF YOUR CODE
}
}
#Fygo is absolutely correct. In your enterframe handler, instead of getting a reference to the Tween you started in the click handler, you are in fact creating a new Tween which you then kill immediately, rather than the original Tween which continues to execute.
I think the following will fix it:
// ... Rest of your code
function rijden(e:MouseEvent):void {
// start the tween on mouse click
TweenLite.to(auto, 4, {x:666.15, y:375.6});
}
addEventListener(Event.ENTER_FRAME, einde1);
function einde1(e:Event){
if(auto.hitTestObject(stopauto)){
// Objects have collided so stop the tween
TweenLite.killTweensOf(auto);
// Place the object somewhere else
auto.x = 241;
auto.y = 375;
removeEventListener(Event.ENTER_FRAME, einde1)
}
}

Flash action script tweenlite 1084:

I'm new to action script
I have a problem with action script 3.0
I got the error
Scene 1, Layer 'actions', Frame 1, Line21 1084: Syntax error: expecting rightbrace before y
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
i cant get to 1 screen its on a loop i thought that it would be over with the gotoandstop but it doesnt
import flash.events.MouseEvent;
import com.greensock.*;
stop();
button1.addEventListener(MouseEvent.CLICK, button1_clicked);
function button1_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:141.35, y:balk_mc.y});
gotoAndStop("page1");
}
button2.addEventListener(MouseEvent.CLICK, button2_clicked);
function button2_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:330.6, y:balk_mc.y});
gotoAndStop("page2");
}
button3.addEventListener(MouseEvent.CLICK, button3_clicked);
function button3_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
gotoAndStop("page3");
}
var number:Number = 1;
next_btn.addEventListener(MouseEvent.CLICK, nextImage);
checkNumber();
function nextImage(event:MouseEvent):void {
//trace("next button geklikt!");
number++;
loader.source = "images/tommorrowland"+number+".png";
checkNumber();
}
previous_btn.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent):void {
//trace("previous button geklikt!");
number--;
loader.source = "images/tommorrowland"+number+".png";
checkNumber();
}
function checkNumber():void {
next_btn.visible = true;
previous_btn.visible = true;
if(number == 4){
next_btn.visible = false;
}
if(number == 1){
previous_btn.visible = false;
}
}
}
}
button4.addEventListener(MouseEvent.CLICK, button4_clicked);
function button4_clicked(e:MouseEvent):void{
TweenLite.to(balk_mc, 1, {x:735 y:balk_mc.y});
gotoAndStop("page4");
}
It's clear that you are new to not only Actionscript, but to StackOverflow too. This website isn't designed to help you find your spelling or typing mistakes. Please revise your code before asking a question every time you get an error. Do some research.
This is the last time I or anyone else will help you with this kind of question. You are missing a comma before y.
Change this line:
TweenLite.to(balk_mc, 1, {x:551 y:balk_mc.y});
with this one
TweenLite.to(balk_mc, 1, {x:551, y:balk_mc.y});
And next time read your own code yourself please.

ActionScript 3.0 - 2 gotoAndPlay() commands in one function

I have the following Adobe Flash (ActionScript 3.0) movie:
When a button is pressed I want to play frame 17 to 24, and after this, I want to go back and play frame 10 to 16 in the same animation. I've tried something like this but unfortunately doesn't works:
button.addEventListener(MouseEvent.CLICK, buttonClick);
function buttonClick(event:MouseEvent):void{
gotoAndPlay(17);
gotoAndPlay(10);
}
In other short words: after gotoAndPlay(17); I want to gotoAndPlay(10);
Thanks for your attention!
Try this:
stop();
// Properties.
var queue:Array = [];
var currentBlock:Point;
// Queue a section of timeline to play.
function queueBlock(start:int, end:int):void
{
queue.push(new Point(start, end));
}
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event):void
{
if(!currentBlock)
{
if(queue.length > 0)
{
// Select and remove first block to play.
currentBlock = queue[0];
queue.splice(0, 1);
gotoAndPlay(currentBlock.x);
}
}
else
{
play();
if(currentBlock.y == currentFrame)
{
// Got to the end of the block, end it.
currentBlock = null;
stop();
}
}
}
Which will let you do this:
// Demo:
queueBlock(17, 24);
queueBlock(10, 16);