简体   繁体   中英

add url for the button inside movieclip which is inside another movieclip in Actionscript 3

I'am trying to create a scrolling thumbnail navigation bar for my website, and I can't add the URL for my button (an image) which is inside the movie clip (which is inside yet another movie).

I tried to use the code : addChild but the program keeps saying :

Scene 1, Layer 'Layer 2', Frame 1, Line 3, Column 12    
1046: Type was not found or was not a compile-time constant: holder3.

the code which i'm using :

var image1:holder3 = new holder3();

holder3.addChild(image1);

image1.i1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_5);

function fl_ClickToGoToWebPage_5(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");
}

I've tried this code (like in Action Script 2):

holder3.holder2.holder1.i1.addEvent

But it doesn't work either.

Before speaking about your code, I think that you have a conflicts in classes and MovieClip instances names because the name of a MovieClip instance and the class name should be different and I think this resolve in many cases the 1046 AS3 error : 1046: Type was not found or was not a compile-time constant .

To explain, take this example :

I drawed a red rectangle on my main stage , then I pressed F8 to convert it to a Symbol ( a MovieClip in my case ), I got a window, in the Name text field I wrote "clp_red" and into the ActionScript Linkage , I checked Export for ActionScript which enable the Class text field where I put "CLP_RED" ( I used uppercase to make difference with the Name but we can use the same value here ). Then I want to insert this new MovieClip into another one ( a MovieClip that contain a blue rectangle for example ), I dragged and dropped it ( the red rectangle MC) as a new instance with the name "red_01". Here for the instance name, you should NEVER use the item class name.

So for your case, try to rename class names as clp_holder3 , clp_holder2 , clp_holder1 and clp_img ( for example ) and when you want to use an instance you should use another name like holder3 , holder2 , ..

Tip : To rename a class, go to your library, double click on the AS Linkage column for you item and then type the new name but you don't need to touch the Name column.

Return now to your code, I think that you have already a holder3 instance in your stage that's why you try to add a new instance of the same object ( as image1 in your code ) to it. Here you should understand that you can not do it like this. Whether you insert holder3 instance manually in your stage or you create it dynamically with AS code.

So for the 1st case ( I dragged and dropped a holder3 instance from my library ), I named it holder3 and It's class name is clp_holder3 , so the right code should be :

holder3.holder2.holder1.i1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_5)
function fl_ClickToGoToWebPage_5(event:MouseEvent):void {
    navigateToURL(new URLRequest('http://www.example.com'), '_blank');
}

In the 2nd case, I dont have anything in my stage, so we should do like this :

var holder3:clp_holder3 = new clp_holder3() // here we create a new instance of our clp_holder3 class and we name it as holder3
stage.addChild(holder3)                     // here we add it to our stage
// you can also do : addChild(holder3)

// and then the same code as the first case
holder3.holder2.holder1.i1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_5)
function fl_ClickToGoToWebPage_5(event:MouseEvent):void {
    trace('before navigateToURL')
    navigateToURL(new URLRequest('http://www.example.com'), '_blank')
    trace('after navigateToURL')
}

I hope this was clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM