javascriptcanvascreatejsadobe-animate

How to access createjs instance from zim npm


My project is developed using createjs in react framework. I have added zimjs npm in my project. on console.log(zim) I found zim object contains window.createjs, I can't figure out how to access createjs library. I don't anything for this in zim docs. I tired zim.createjs, window.createjs nothing works.


Solution

  • ZIM now has templates for React, Angular, Vue and Svelte using NPM - please see the GitHub repository for the templates: https://github.com/danzen/zimjs-templates. It will be something like this (and will call CreateJS automatically):

    <script>
        import { Component, ReactNode, StrictMode } from "react";
        import "./App.css";
        import zim from "zimjs";
        class ZimFrame extends Component {
          frame: zim.Frame | undefined;
      
          componentDidMount(): void {
              this.frame = new zim.Frame({
                scaling: "zim",
                width: 500,
                height: 400,
                color:light,
                ready: () => {
                    // put code here
                    new zim.Circle(50, red).center().drag();
                }
              });
          }
          componentWillUnmount(): void {
              this.frame?.dispose();
          }
          render(): ReactNode {
              return null;
          }
        }
        function App() {
          return (
              <>
              <div>
                  {/* Move StrictMove from the root to here */}
                  <StrictMode>
                  <div id='zim'></div>
                  </StrictMode>
                  {/* Include ZIM code outside StrictMode */}
                  <ZimFrame />
              </div>
              </>
          )
        }
        export default App;
    </script>