Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

How to reach Scrollpane out of a MovieClip

Hello,

please can somebody help me?

I have an AS3 application. In root ( i know in AS3, root is called by a new name) i add a Scrollpane. How can i call the Scrollpane from another MovieClip.

parent.parent.myScroller.update(); is not working!

How can i solve this?

Thank´s in advance!

Regards,
Mario
0
20one
Asked:
20one
  • 29
  • 27
  • 2
2 Solutions
 
sajayj2009Commented:
MovieClip(this.parent.parent).myScroller.update();
0
 
20oneAuthor Commented:
Thank you for your answer. I have try your solution, but i get an error:

TypeError: Error #1034: Typumwandlung fehlgeschlagen: flash.display::Sprite@4cfe95b1 kann nicht in flash.display.MovieClip umgewandelt werden.
      at index_fla::mainNavi_25/doClick()

Sorry it´s in german.
0
 
20oneAuthor Commented:
This is the function, where i have put the updater.
function doClick(event:MouseEvent):void{
	var currentBtn:int = event.currentTarget.id;
	setSelectedBtn(currentBtn);
	MovieClip(this.parent.parent).scroller.update();
}

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sajayj2009Commented:
MovieClip(root).scroller.update();
0
 
sajayj2009Commented:
(root as MovieClip).scroller.update();

This too work.
0
 
20oneAuthor Commented:
Thank´s again, but both doesn´t work.

(root as MovieClip).scroller.update(); i get this error:

TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
      at index_fla::mainNavi_25/doClick()

MovieClip(root).scroller.update(); i get this error:

TypeError: Error #1034: Typumwandlung fehlgeschlagen: flash.display::Stage@4cfe4ba1 kann nicht in flash.display.MovieClip umgewandelt werden.
      at index_fla::mainNavi_25/doClick()
0
 
20oneAuthor Commented:
This my code in root, in the first frame:

import fl.containers.ScrollPane;
import fl.controls.ScrollPolicy; 
import fl.events.ScrollEvent; 

// Benötigte Variablen definieren
var scroller:ScrollPane = new ScrollPane();

scroller.setSize(stage.stageHeight,stage.stageWidth);
scroller.width = stage.stageWidth;
scroller.height = stage.stageHeight;
scroller.verticalScrollPolicy = ScrollPolicy.ON;
scroller.horizontalScrollPolicy = ScrollPolicy.OFF;

scroller.addEventListener(ScrollEvent.SCROLL, scrollListener); 

scroller.addEventListener(Event.COMPLETE, completeListener); 
scroller.source = Container; 

function scrollerUpdaten() {
	scroller.update();
}

Open in new window

0
 
sajayj2009Commented:
is scroller instance name correct?
0
 
20oneAuthor Commented:
yes, i have declare the var scroller.
0
 
sajayj2009Commented:
Can you give this funtion also here?

function doClick(event:MouseEvent):void{
}
0
 
sajayj2009Commented:
Here like this;
import fl.containers.ScrollPane;
import fl.controls.ScrollPolicy; 
import fl.events.ScrollEvent; 

// Benötigte Variablen definieren
var scroller:ScrollPane = new ScrollPane();

scroller.setSize(stage.stageHeight,stage.stageWidth);
scroller.width = stage.stageWidth;
scroller.height = stage.stageHeight;
scroller.verticalScrollPolicy = ScrollPolicy.ON;
scroller.horizontalScrollPolicy = ScrollPolicy.OFF;

scroller.addEventListener(ScrollEvent.SCROLL, scrollListener); 

scroller.addEventListener(Event.COMPLETE, completeListener); 
scroller.source = Container; 

function scrollerUpdaten() {
        scroller.update();
}

function doClick(event:MouseEvent):void{
        var currentBtn:int = event.currentTarget.id;
        setSelectedBtn(currentBtn);
        MovieClip(this.parent.parent).scroller.update();
}

Open in new window

0
 
20oneAuthor Commented:
Here it is:

function doClick(event:MouseEvent):void{
	var currentBtn:int = event.currentTarget.id;
	setSelectedBtn(currentBtn);
	//MovieClip(root).scroller.update();
//(root as MovieClip).scroller.update();
}

Open in new window

0
 
20oneAuthor Commented:
ok, one moment, i will try it.
0
 
sajayj2009Commented:
Button are at root, right?
0
 
20oneAuthor Commented:
No the Buttons are not in root. I will show you ...

The Buttons are stored in "root.Container.manNavi" and the code for the Scrollpane is stored in root.
If i move the doClick function to root, how can i call then the functions they are stored in "root.Container.mainNavi"?

Here is the code of the Buttons/menu:

var buttonsArray:Array = [btn1,btn2,...];

function setButtons():void {
	for (var i:int=0; i<buttonsArray.length; i++) {
		buttonsArray[i].id = i;
		buttonsArray[i].buttonMode = true;
		buttonsArray[i].mouseChildren = false;
		buttonsArray[i].mouseEnabled = true;
		buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
		buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
		buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
	}
}

function playOver(event:MouseEvent):void {
	event.currentTarget.gotoAndPlay("over");
}

function playOut(event:MouseEvent):void {
	event.currentTarget.gotoAndPlay("out");
}

function doClick(event:MouseEvent):void{
	var currentBtn:int = event.currentTarget.id;
	setSelectedBtn(currentBtn);
	//MovieClip(root).scroller.update();
}
function setSelectedBtn(id:int):void{
	for (var i:int=0; i< buttonsArray.length; i++) {
		if (id == i) {
			buttonsArray[i].gotoAndStop("down");
			buttonsArray[i].buttonMode = false;
			buttonsArray[i].mouseEnabled = false;
			buttonsArray[i].removeEventListener(MouseEvent.ROLL_OVER,playOver);
			buttonsArray[i].removeEventListener(MouseEvent.ROLL_OUT,playOut);
			buttonsArray[i].removeEventListener(MouseEvent.CLICK,doClick);
		} else {
			if(buttonsArray[i].currentLabel =="down"){
				buttonsArray[i].gotoAndPlay("out");
			}
			buttonsArray[i].buttonMode = true;
			buttonsArray[i].mouseEnabled = true;
			buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
			buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
			buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
		}
	}
}
setButtons();

Open in new window

0
 
20oneAuthor Commented:
Are you still here?
0
 
sajayj2009Commented:
Did you trace the level of your buttons?
0
 
20oneAuthor Commented:
No i have not. Please can you show me hot to do?
0
 
20oneAuthor Commented:
hot = how
0
 
sajayj2009Commented:
trace(buttonsArray[i]) inside setButtons function
0
 
20oneAuthor Commented:
Thank´s for the answer. I´m on the way to the doctor. I will be back at 08.00 a.m. (gmt +1) and i will get back to you then.
0
 
sajayj2009Commented:
gmt+5 here
0
 
20oneAuthor Commented:
Thank´s for waiting...
The result is: [object buttonFilmball_28]
0
 
sajayj2009Commented:
So buttonFilmball_i's are the buttons you are referrring about?
0
 
20oneAuthor Commented:
Yes it is, if i click one of these buttons, the scroller have to make an update.
0
 
sajayj2009Commented:


function doClick(event:MouseEvent):void{
        var currentBtn:int = event.currentTarget.id;
        setSelectedBtn(currentBtn);
        scroller.update();
}
0
 
sajayj2009Commented:
since buttons are generated in root itself
0
 
sajayj2009Commented:
trace(buttonFilmball_i) in same place [inside if loop]
0
 
sajayj2009Commented:
function doClick(event:MouseEvent):void{
        var currentBtn:int = event.currentTarget.id;
        setSelectedBtn(currentBtn);
trace(currentBtn);
        scroller.update();
}
0
 
sajayj2009Commented:
Please check with trace() the level and values from each function, you can also check inside your container where you mentioned before.
0
 
20oneAuthor Commented:
But if i put the doCLick function in root, i can´t reach the other functions, (placed in another mc´s) which depends on the doCLick function. Please can i give you a fla-File?
0
 
sajayj2009Commented:
ok, post fla
0
 
20oneAuthor Commented:
Here it is.

test.fla
0
 
sajayj2009Commented:
Hi U there?

In this file, could you plz tell me working model.

When I clicked one of top links, Scrollpane is enabled..Is that? State problem also..
0
 
20oneAuthor Commented:
Yes i´m ;)

If you click one of the buttons, a depending content is loading. Every content has a different height, so the scrollpane has to have the height of the actual loaded content. The content is added to the scrollpane (inside it).

This function works with scroller.update(); i have it in my onresize function. But i also need it when a button is clicked.
0
 
sajayj2009Commented:
Yes when i clicked a button, the scrollpane came there.
0
 
sajayj2009Commented:
Sorry, it is coming at begining itself.
0
 
20oneAuthor Commented:
No, the scrollpane is always on.
But if you click some button, diferent contents are loaded, with different height. And now the scroller has to be updated.

Bild-3.png
0
 
20oneAuthor Commented:
Do you see the different?
Bild-4.png
0
 
20oneAuthor Commented:
And this has to happend on a button click, not onl in the onresize function.
0
 
20oneAuthor Commented:
I know 100% that this can be made with the update function. But the problem is to reach this function in root, from the mainNavi mc.
0
 
sajayj2009Commented:
Yes I know, I am getting a conflict here.

A conflict exists with definition scroller in namespace internal.
0
 
20oneAuthor Commented:
I don´t know to fix it. I try it since 2 days ...
0
 
sajayj2009Commented:
Try this.

Note:

go to the publish settings in flash -> Flash Tab -> Settings (next to Actionscript 3.0) -> uncheck Automatically declare stage instances. Just make sure you declare your mc in the class as public.


function doClick(event:MouseEvent):void{
      var currentBtn:int = event.currentTarget.id;
      setSelectedBtn(currentBtn);
      //MovieClip(this.parent.parent).scroller.update();
      //MovieClip(this.parent.parent).scrollerUpdaten();
      (root as MovieClip).scroller.update();
}
0
 
20oneAuthor Commented:
Thank´s, i have try it, but it´s not working ... My head is breaking up in two pieces.

Error:
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
      at index_fla::mainNavi_27/doClick()
0
 
sajayj2009Commented:
20one,

actually code is working, but it is not taking that scrollpane name.
0
 
20oneAuthor Commented:
I know, but i don´t know why. Everything is right. The instance have a name, the functions are ok, ... I don´t know what to do.
0
 
sajayj2009Commented:
Are you still getting that conflict?
0
 
20oneAuthor Commented:
yes. sorry i have to go now again to the doctor, i´m ill. please can we talk tomorrow again?
0
 
sajayj2009Commented:
I will be out for 2 days. Thats why I am here till now...
0
 
sajayj2009Commented:
20one,

do you see <request attention> link on next to your question on top?

Click and post a request to moderators.
0
 
20oneAuthor Commented:
OK, thank´s i will do. If i can´t solve the problem till sunday, please come back again.

Thank´s anyway ...

Regards!
0
 
sajayj2009Commented:
You will get a response for sure, do not worry. I will be back by tuesday only.
0
 
20oneAuthor Commented:
Please, is there anybody who can help me, solving the problem?
0
 
blue-genieCommented:
>> A conflict exists with definition scroller in namespace internal.

you have  a scrollpane on the stage called scroller on the stage, and you declare and add one with code, hence the conflict.

so pick one or the other, if you choose to use the place on stage manually option, remember to give it time to instantiate before you try to add listeners to it otherwise you'll end up with a null exception.

Then I'm not sure what the final product is supposed to look like or what it's supposed to do but if you want to access the updateScroller function in the main timeline from your click function just do this.

event.currentTarget.root.scrollerUpdaten();

0
 
20oneAuthor Commented:
Thank you for the answer. I have delete the instance name of the scroller. I only left the var in code. But i also have the same problems to call the scroller function. Here is the Error:

ReferenceError: Error #1069: Eigenschaft scrollerUpdaten für flash.display.Stage nicht gefunden und es ist kein Standardwert vorhanden.
      at index_fla::mainNavi_27/doClick()

I have choose your solution (event.currentTarget.root.scrollerUpdaten();), but it don´t works.
Please can you take a look at my attached Fla and try it by yourself?

Regards!
0
 
20oneAuthor Commented:
I have move now the code from the manNav to the Main Timeline. I think it´s the fastest solution.
Thanks anyway for helping so much!!!
0
 
blue-genieCommented:
as i mentioned i couldn't get anything to happen inside your scrollbar, but if i put a trace action inside your scrollerUpdaten function you'll see it gets triggered, so that means you can access the function.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 29
  • 27
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now