Copy link to clipboard
Copied
So, my code is a bloody mess due to me being new, but bare with me..
I'm trying to create a grid of changeable icons using buttons and named frames, rather than making a unique menu to change each icon, I'm trying to define a variable called hexTarget.
the trouble ensues when I try to reference this target in another MOvie Clip because they're not in the same parent line.
hexTarget is created in MovieClip(root).Grid_mc.Menu_mc
But is set on press in MovieClip(root).Grid_mc.Button1_mc
On press it sets the variable hexTarget to "Button1_mc" and on trace I can see this is working, the trouble I'm having is I don't know how to reference this variable to then go back and set Button1_mc to a certain frame.
PMPL_barren_btn.addEventListener (MouseEvent.MOUSE_DOWN, setHex_PMPL_barren);
function setHex_PMPL_barren (event:MouseEvent):void{
gotoAndStop (1);
//trace(MovieClip(root).Grid_mc.Menu_mc.hexTarget);
MovieClip(root).Grid_mc.Menu_mc.hexTarget.gotoAndStop ('PMPL_barren')
I don't even know if this is possible (But I have had it work in other test fla's where the var is in the same chain of MC's) or if there's a better way to approach this, but I really appreciate any input you peeps might have
Got it!
Before anything: really great design!!! Congrats!
Here is a suggestion of how this can be achieved.
Preview:
FLA download:
animate_cc_as3_hexagonal_grid.zip - Google Drive
Code:
...import flash.events.MouseEvent;
import flash.display.MovieClip;
var currentHexagon:MovieClip;
var currentHighlight:MovieClip;
function mouseHandler(e:MouseEvent):void
{
if (e.type == MouseEvent.MOUSE_OVER)
{
(e.target as MovieClip).gotoAndStop("over");
if (e.currentTarget == popup.highlights)
Copy link to clipboard
Copied
Okay, so I made some headway by translating the target path into another variable so I could phrase it as targPath[hexTarget].gotoAndStop(2)
It's working but still throwing #1010 errors in output for
at SB_Utility_fla::mcHexN1P0_7/frame2()
at flash.display::MovieClip/gotoAndStop()
at SB_Utility_fla::mcPopMenuBG_11/setHex_PMPL_barren()
// I had simplified MC names for the sake of reading for this post
Am I doing something wrong or are #1010 errors okay to ignore if everything is running properly?
After toying with something.. It no longer works T_T
Copy link to clipboard
Copied
After playing with this further trying to recreate success, it appears it's only possible if all elements are on the same relative level 😕
If there's a cleaner way to try and do this I'd love to have some feedback (This is all Timeline code, last time I was working with Flash was back in MX and I don't fully understand .as and classes)
Copy link to clipboard
Copied
Hi.
I really didn't get what you want to do.
Can you share your FLA and give us a short explanation?
Thank you.
Copy link to clipboard
Copied
Uhh, not sure how to share my FLA.. But I can probably explain what I'm trying to do a bit better..
I'm trying to create a hexagonal grid of Movie Clips that I can click on to bring up a menu and assign an icon to each position individually.
Currently I have a button for each grid placement with it's own instance name, when I click one it brings up a Pop Menu and sets the var hexTarget to the grid co-ordinate I clicked on, I go through the Pop Menu and select the icon I want in that spot and then it hides the menu and uses the value of the variable hexTarget to point back to that Movie Clip and sets it to the matching frame. (using the code MovieClip(root).Grid_mc.???[hexTarget].gotoAndStop ('matching_Frame')
I've tried swapping ??? for a bunch of different things incl. just putting the entire address in the variable (which I thought would work :S)
All in all I'm trying to get this method to work so I don't have to create a seperate Pop Menu for every grid position, even though I've spent so much time on it now it would have been quicker to do so lol.
Here's an image for reference, cheers
Copy link to clipboard
Copied
Got it!
Before anything: really great design!!! Congrats!
Here is a suggestion of how this can be achieved.
Preview:
FLA download:
animate_cc_as3_hexagonal_grid.zip - Google Drive
Code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
var currentHexagon:MovieClip;
var currentHighlight:MovieClip;
function mouseHandler(e:MouseEvent):void
{
if (e.type == MouseEvent.MOUSE_OVER)
{
(e.target as MovieClip).gotoAndStop("over");
if (e.currentTarget == popup.highlights)
currentHighlight = (e.target as MovieClip);
}
else if (e.type == MouseEvent.MOUSE_OUT)
(e.target as MovieClip).gotoAndStop("up");
else if (e.type == MouseEvent.MOUSE_DOWN)
{
if (e.currentTarget == popup.closeButton)
dismissPopup();
if (e.currentTarget == popup.highlights)
setIcon(e.target as MovieClip);
else if (e.currentTarget == grid)
callPopup(e.target as MovieClip);
}
}
function callPopup(hexagon:MovieClip):void
{
currentHexagon = hexagon;
currentHexagon.gotoAndStop("down");
popup.x = currentHexagon.x;
popup.y = currentHexagon.y;
popup.visible = true;
gridListeners("removeEventListener");
iconsListeners();
}
function dismissPopup():void
{
currentHighlight.gotoAndStop(1);
currentHexagon.gotoAndStop(1);
popup.visible = false;
gridListeners();
iconsListeners("removeEventListener");
}
function setIcon(icon):void
{
currentHexagon.icons.gotoAndStop(popup.highlights.getChildIndex(icon) + 1);
dismissPopup();
}
function gridListeners(method:String = "addEventListener"):void
{
grid[method](MouseEvent.MOUSE_OVER, mouseHandler);
grid[method](MouseEvent.MOUSE_OUT, mouseHandler);
grid[method](MouseEvent.MOUSE_DOWN, mouseHandler);
}
function iconsListeners(method:String = "addEventListener"):void
{
popup.highlights[method](MouseEvent.MOUSE_OVER, mouseHandler);
popup.highlights[method](MouseEvent.MOUSE_OUT, mouseHandler);
popup.highlights[method](MouseEvent.MOUSE_DOWN, mouseHandler);
}
popup.visible = false;
gridListeners();
popup.closeButton.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
I hope it helps and don't hesitate to ask if you have any further questions.
Regards,
JC
Copy link to clipboard
Copied
Cheers mate, should've just asked around a long time ago
I don't understand the majority of the code but it's at least something to reverse engineer and work with ^^
Was just this 1 hurdle holding back my project haha
Copy link to clipboard
Copied
Haha! No problem! I'm glad you liked it!
You can ask me anything about this code or other issues you may find in you program. Just let me know.
Regards,
JC